January 17th, 2013, 04:14 PM
Issue clearing list
I'm in a loop and want to clear list1 after I append to list2.
list1 = 
list2 = 
for i in range(0, 100)):
list2 .append(list1 )
# at this point I want to clear list1 for the next iteration.
# any of the following clears list1 but also clears list2.
# I want list2 to remain untouched.
del list1 [:]
# my current work around is to do a list1= each iteration but
# that creates another instance of list1 and I don't want that.
January 17th, 2013, 06:14 PM
and removes/garbage collects the previous instance leaving one only. You can also do
## don't use "i" ,"l" or "o" as they look like numbers
for ctr in range(0, 100)):
## or list comprehension
list2 = [[var1, var2] for ctr in range(100)]
Last edited by dwblas; January 17th, 2013 at 06:17 PM.