In other words lst is a global variable, where as cnt2 is a local variable
to just the list comps completion of the data being diplayed in the list
comp, with each cnt2 in the global var lst being contained in the list
comp, but only accessible through iteration/placing/splicing of the lst
variable that corresponds within the lst global variable which uses list
methods.


On Thu, Aug 8, 2013 at 12:15 AM, David Hutto <dwightdhu...@gmail.com> wrote:

> if the variable is the range in the first one, then just don't append it,
> and replace it with something else.
>
> The second, you use cnt2, but it is a part of the the list comp, but not a
> variable:
>
> #this is in [ython 3, but you can import from future, or remove quotes
> from print parameters
> lst = [cnt2 for cnt2 in range(5)]
> print(lst)
>
> you want cnt2, but cnt2 is in the list comprehension, so it is a variable
> within the list comp, but after it has been used there, then you need to
> iterate through the list(lst), in order to find particular cnt's within the
> lst list of cnt2 variables..
>
>
>
> On Wed, Aug 7, 2013 at 11:54 PM, Jim Mooney <cybervigila...@gmail.com>wrote:
>
>> This bugs me for some reason. The final variable is saved in a for
>> loop but not in a list comprehension. It just seems to me they should
>> both be destroyed to avoid confusion.
>>
>> lst = []
>> for cnt in range(5):
>>     lst.append(cnt)
>> cnt
>> 4
>>
>> lst = [cnt2 for cnt2 in range(5)]
>> cnt2
>> builtins.NameError: name 'cnt2' is not defined
>>
>> Is there a form of for loop that would destroy the loop variable? I
>> could always do del cnt right after the for, but that seems
>> artificial.
>>
>> --
>> Jim
>> _______________________________________________
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
> --
> Best Regards,
> David Hutto
> *CEO:* *http://www.hitwebdevelopment.com*
>



-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to