I've been doing competitive programming (USACO) for a couple of months now, in which there are time constraints you cannot exceed. I need to create a large matrix, or 2d array, the dimensions being 2500x2500, in which each value is [0,0]. Using list comprehension is taking too much time, and I needed an alternative (you cannot import modules so numpy isn't an option). I had initially done this:
grid = [[[0,0] for i in range(2500)] for i in range(2500)]
but it was taking far too much time, so I tried:
grid= [[[0,0]]*2500]*2500
,
which gives the same result initially, but whenever I try to change a value, for example:
grid[50][120][0]= 1
, it changes the 0th index position of every [0,0] to False in the entire matrix instead of the specific coordinate at the [50][120] position, and this isn't the case when I use list comprehension. Does anybody know what's happening here? And any solution that doesn't involve a crazy run time? I started python just a couple of months before competitive programming so I'm not super experienced.