Hopefully not too basic of a Python question, but I stumbled upon this while writing a function and am a bit confused.
I am trying to run through a for loop and create multiple lists where the first item is the same. If I use this method, all seems fine.
current_list = [1]
for each in range(5):
each = current_list + [each]
print(each)
[1, 0]
[1, 1]
[1, 2]
[1, 3]
[1, 4]
But if I try to make a copy of the list and append to it, I get None
current_list = [1]
for each in range(5):
each = current_list.copy().append(each)
print(each)
None
None
None
None
None
Do I need to deep copy the list? What is the best way to copy the contents of the list?