Pushing to an array which is an element of another array (Modifying an array in an array)

Also, don’t use fill here. It will create an array of references to the same single array. So pushing to one of them, will be visible everywhere.

Use an array comprehension instead.

And, as @lmiq says, [] are not good here. Whenever you see [] in your code, it’s a bad sign.

1 Like