How to Create a List of Lists in Python
Rows and columns, such as seats in a cinema or cells in a table, fit naturally into a list whose items are lists themselves. This guide builds one in Python 3.15.2 and reads a row, a single item, and the number of rows and columns.
Syntax
<name> = [[<item>, <item>], [<item>, <item>]]
<name>[<row>]
<name>[<row>][<column>]
| Part | What it means |
|---|---|
[[...], [...]] | An outer list whose items are lists: one inner list per row |
<name>[<row>] | One whole row, counting from 0 |
<name>[<row>][<column>] | One item: the row first, then the position inside that row |
The Python tutorial says: "It is possible to nest lists (create lists containing other lists)".
The Example
A small cinema has two rows of three seats, A1 to A3 and B1 to B3. The script prints the whole plan, the first row, the last seat of the second row, and the number of rows and seats per row.
Prerequisites
- uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with
uv init.
Step 1: Write the Script
seats = [["A1", "A2", "A3"], ["B1", "B2", "B3"]]
print(seats)
print(seats[0])
print(seats[1][2])
print(len(seats), len(seats[0]))
![The grid.py script in a macOS-style code window: seats is a list of two lists, A1 to A3 and B1 to B3; the script prints seats, seats[0], seats[1][2], and len(seats) with len(seats[0]).](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/programming/python/2026/python-list-of-lists-01-code.webp)
Step 2: Run It
uv run python grid.py
[['A1', 'A2', 'A3'], ['B1', 'B2', 'B3']]
['A1', 'A2', 'A3']
B3
2 3

seats[0]is the first inner list, the whole A row.seats[1][2]takes the second row ([1]), then its third seat ([2]):B3. Positions start at 0.len(seats)counts the rows, 2, andlen(seats[0])counts the seats in the first row, 3.
The command works unchanged in PowerShell.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Building rows with [[0] * 3] * 2 | Both rows are the same list: after rows[0][0] = 9, it printed [[9, 0, 0], [9, 0, 0]] | [[0] * 3 for _ in range(2)] makes a new list per row: it printed [[9, 0, 0], [0, 0, 0]] |
Swapping the indexes, seats[2][1] | IndexError: list index out of range: there is no third row | Row first, then column |
| Rows of different lengths | len(seats[0]) no longer tells you every row's length | Keep the rows the same length when they stand for a grid |
FAQ
Can the inner lists hold different types?
Yes. Each inner list is an ordinary list, so it can hold numbers, text or anything else.
How do I add a row?
Append a list to the outer list: seats.append(["C1", "C2", "C3"]).
Conclusion
seats = [["A1", "A2", "A3"], ["B1", "B2", "B3"]] held two rows. seats[0] gave the first row, seats[1][2] gave B3, and len() gave 2 rows of 3 seats.
Additional Resources
- Lists in the Python tutorial — nesting included.
- More on lists —
append()and the other list methods. - Nested list comprehensions — building a list of lists in one expression.
