3 ms·
That's not a bug, it's just the result of Python variables being references to values, instead of actual values. When you write "[[]]", what you're doing is cre
by icebraining 13y ago
That's not a bug, it's just the result of Python variables being references to values, instead of actual values. When you write "[[]]", what you're doing is creating a list that holds a reference to another list.
If you use a variable it's easier to understand:
a = []
arrays = [a] * 5
What you have now is [a, a, a, a, a], so if you modify one of the lists, it's no wonder they all get modified: they're references to the same list.