I have an array in python(pygame):


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?

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.


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