Question: I am attempting to initialize a list and keep getting the index out of range:

```
self.nodes = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]]

```

When I run this code:

```
for i in range(self.rows):
            for j in range(self.columns):
                if self.GRID[i][j] == 0:
                    self.walkable.append(Node(j * self.cellSize, i * self.cellSize))
                    self.isWalkable = True
                if self.GRID[i][j] == 1:
                    self.unwalkable.append(Node(j * self.cellSize, i * self.cellSize))
                    self.isWalkable = False
                if self.GRID[i][j] == 2:
                    self.player = Node(j * self.cellSize, i * self.cellSize)
                    self.isWalkable = True
                if self.GRID[i][j] == 3:
                    self.npc = Node(j * self.cellSize, i * self.cellSize)
                    self.isWalkable = True

                self.nodes[i][j] = Node(j, i)
                self.nodes[i][j].setWalkable(self.isWalkable)

```

The error I get is:

```
self.nodes[i][j] = Node(j, i)
IndexError: list assignment index out of range

```

Answer: 
Assignment to a non-existent index in a list fails. In your case, you are attempting to assign to index `j` of an empty list:

```
self.nodes = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]]
# assume i == 0 and j == 0
self.nodes[i] # refers to the first empty list []
self.nodes[i][j] ## does not exist

```

Consider replacing `self.nodes[i][j] = Node(j, i)` with `self.nodes[i].append(Node(j, i))`

Alternatively, ensure that `self.nodes` is initialised with nested lists as described by @yi\_H

**EDIT** OK, not *exactly* as yi\_H described. If you want to create a 2d array representing your table, you can do so with

```
self.nodes = [ [None for col in range(self.cols) ] for row in range(self.rows)]

```
```
self.nodes = [[[]] * self.columns] * self.rows

```