[Tutor] inconsistent destruction
Jim Mooney
cybervigilante at gmail.com
Thu Aug 8 05:54:26 CEST 2013
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
More information about the Tutor
mailing list