Initialize an array of arrays:
M = [[]]*(24*60/5)
Append the number 2 to the 51st array in M
M[50].append(2)
What is in M?
...
[2]
[2]
[2]
[2]
[2]
[2]
[2]
[2]
...
Every element in M is the array [2]
What am I missing? I suspect that every [] that I initially initialize is a reference to the same space in memory.
You did create an array of arrays. But you then assigned the same
[]to every one of its entries.It’s not that every time you call
[]it gives you the same array – it’s that you only called[]once.Get it?