def create_grid(locked_positions = {}):
grid = [[(0, 0, 0) for x in range(10)] for x in range(20)]
for i in range(len(grid)):
for j in range(len(grid[i])):
if (j, i) in locked_positions:
c = locked_positions[(j,i)]
grid[i][j] = c
return grid
Dictionary data locked_positions = {} and
If (j, i) in locked_positions: I don't quite understand this…
Please tell me how to find the conditional sentence.
python
locked_positions = {} in a function declarationThis part is to set locked_position to empty dictionary by default if the parameter has no value. Of course, I use the value when the dictionary comes in as a parameter. Looking at the code, locked_positions seem to be a dictionary in the form of (x, y) : (0, 0, 0
In that way, if(j, i) in locked_position, it seems to be determined whether or not the key value exists in the general dictionary.
© 2024 OneMinuteCode. All rights reserved.