Jan-27-2017, 05:29 PM
(Jan-27-2017, 09:43 AM)ichabod801 Wrote: The first way doesn't work because [[0] * n] creates a mutable list of zeros once. Then when the second *n copies the list, it copies references to first list, not the list itself. So you have a list of references, not a list of lists. The second way a new [0] * n is created each time through the loop. That way there is no copying being done, so you end up with an actual list of lists. I often do the second way with a list comprehension:[[0] * n for row in n]
So there is no way to do this by one line code unless to use numpy?
L