I have a question for Python.

Asked 2 years ago, Updated 2 years ago, 16 views

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

2022-09-22 20:14

1 Answers

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.


2022-09-22 20:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.