1

I have the following list:

grid = [[0] *50 for n in range(50)]

I want to replace the values in grid (with 1) for each coordinate contained in the list:

area = [(30, 28), (27, 32), (32, 34), (43,23), (43, 2) ...] # Continues on

Is there any simple method that this can be done?

6
  • 1
    Your input is a 50x50 2D list, and your output is of an unknown dimension from what I see from here, can you explain on how you want to convert this Commented May 19, 2019 at 17:05
  • Hi Davesh. For example the value at grid[30][28] would be changed Commented May 19, 2019 at 17:07
  • And you have the values to which it will be changed to as well?, also what kind of coordinate is (43) or (23) ? Commented May 19, 2019 at 17:08
  • I want to change all values in the list area to 1. Commented May 19, 2019 at 17:12
  • Lets add all those details in the question as well Commented May 19, 2019 at 17:12

1 Answer 1

2

A simple for loop is what is needed.

for i,j in area:
    grid[i][j] = 1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.