Now I'm refactoring some code and I found something weird.
I thought the following 2 expressions were exactly same:
list1 = [[0.00] * 5 for _ in range(5)]
list2 = [[0.00] * 5] * 5
I can see they make same results by running:
print(list1 == list2)
or
import numpy as np
print(np.array(list1).shape == np.array(list2).shape)
But in the project I'm revising, list2
doesn't work. When I use it, it raises 'Index out of range'.
Please tell me if 'list1 == list2' as I said, or if I'm wrong about that.
Thanks in advance.
P.S. I can use numpy.zeros()
or some other things, but I'm really curious.