Declaring 100 Python Lists

Asked 2 years ago, Updated 2 years ago, 13 views

Declare the list with Python

list_a = [[0,0,0], [0,0,0], [0,0,0]....[0,0,0]]

I want to make a list like this.

The way I thought of it is

list_a = [[0,0,0]] * 100

If you create it like this, the problem is

list_a[0][1] = 1

If this is the case

list_a = [[0, 1, 0], [0,1,0], [0,1,0]....[0,1,0]]

There was a problem with all the index values changing at once.

For me,

list_a = [[0,1,0], [0,0,0], .... [0,0,0]]

I just wanted to do this.

How can I make 100 lists inside the list that work the way I want?

python

2022-09-21 18:59

1 Answers

It's a self-answer.

list_a = [ [0,0,0] for _ in range(3) ]

Do it like this.


2022-09-21 18:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.