# Pygame array; keeping list items constant

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?

## 1 Answer

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.