0
\$\begingroup\$

I have an array in python(pygame):

Grid=[[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]]

I have written a program that changes some of the values of the array to 1 if certain variables are true. How can I ensure that the first item and the last item in all 3 lists will always remain as 0?

\$\endgroup\$
2
\$\begingroup\$
def ensureZeros(grid):
    for row in grid:
        row[0] = row[-1] = 0

You just need a function that sets the first and last item of each row to zero. Call this whenever you need to ensure that there are zeros in the correct places.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.