To initialize a two-dimensional list in Python, use

t = [ [0]*3 for i in range(3)]

But don't use [[v]*n]*n, it is a trap!

>>> a = [[0]*3]*3
>>> a
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
>>> a[0][0]=1
>>> a
[[1, 0, 0], [1, 0, 0], [1, 0, 0]]
Answer from Jason CHAN on Stack Overflow
๐ŸŒ
Matplotlib
matplotlib.org โ€บ stable โ€บ gallery โ€บ color โ€บ named_colors.html
List of named colors โ€” Matplotlib 3.10.8 documentation
import math import matplotlib.pyplot as plt import matplotlib.colors as mcolors from matplotlib.patches import Rectangle def plot_colortable(colors, *, ncols=4, sort_colors=True): cell_width = 212 cell_height = 22 swatch_width = 48 margin = 12 # Sort colors by hue, saturation, value and name. if sort_colors is True: names = sorted( colors, key=lambda c: tuple(mcolors.rgb_to_hsv(mcolors.to_rgb(c)))) else: names = list(colors) n = len(names) nrows = math.ceil(n / ncols) width = cell_width * ncols + 2 * margin height = cell_height * nrows + 2 * margin dpi = 72 fig, ax = plt.subplots(figsize=(widt
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-using-2d-arrays-lists-the-right-way
Using 2D arrays/lists in Python - GeeksforGeeks
Manually initializing and populating ... a list of size N. ... Explanation: range(N) controls list length. A 2D list represents data in rows and columns....
Published ย  December 20, 2025
Discussions

How to initialize a two-dimensional array (list of lists, if not using NumPy) in Python? - Stack Overflow
List multiplication makes a shallow copy. When you assign to an index, it does a proper change, but access does not, so when you do a[x][y] = 2, it's accessing, not assigning, for the xth index - only the yth access is actually changed. This page helped me explain with diagrams that are probably better than what I tried explaining in this comment: geeksforgeeks.org/python-using-2d... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Explain 2D Lists
Lists contain things. Lists are things. Therefore, lists can contain lists. That's literally all there is to it. More on reddit.com
๐ŸŒ r/learnpython
6
2
August 3, 2014
2D array ( list ) in Python

https://www.reddit.com/r/learnpython/wiki/faq#wiki_why_is_my_list_of_lists_behaving_strangely.3F

More on reddit.com
๐ŸŒ r/learnpython
4
1
March 3, 2018
Why are 2D arrays in Python so stupid?
Because they aren't arrays, and aren't designed to be pre-allocated like that. Generally, if you need matrices use Numpy. More on reddit.com
๐ŸŒ r/learnprogramming
4
0
September 5, 2019
๐ŸŒ
DataCamp
campus.datacamp.com โ€บ courses โ€บ intro-to-python-for-data-science โ€บ chapter-2-python-lists
Python Lists | Python
I just told you that lists can also contain lists themselves. Instead of putting the strings in between the numbers, you can create little sublists for each member of the family. One for liz, one for emma and so on. Now, you can tell Python that these sublists are the elements of another list, that I named fam2: the little lists are wrapped in square brackets and separated with commas.
๐ŸŒ
Udemy
udemy.com
Online Courses - Learn Anything, On Your Schedule | Udemy
Udemy is an online learning and teaching marketplace with over 250,000 courses and 80 million students. Learn programming, marketing, data science and more.
๐ŸŒ
Snakify
snakify.org โ€บ two-dimensional lists (arrays)
Two-dimensional lists (arrays) - Learn Python 3 - Snakify
For example, that's how you display two-dimensional numerical list on the screen line by line, separating the numbers with spaces: ... a = [[1, 2, 3, 4], [5, 6], [7, 8, 9]] for i in range(len(a)): for j in range(len(a[i])): print(a[i][j], end=' ') print() We have already tried to explain that a for-loop variable in Python can iterate not only over a range(), but generally over all the elements of any sequence.
Find elsewhere
๐ŸŒ
GitHub
github.com โ€บ vinta โ€บ awesome-python
GitHub - vinta/awesome-python: An opinionated list of awesome Python frameworks, libraries, software and resources.
2 weeks ago - Arcade - Arcade is a modern Python framework for crafting games with compelling graphics and sound. Cocos2d - A framework for building 2D games, demos, and other graphical/interactive applications.
Starred by 285K users
Forked by 27.3K users
Languages ย  Python 92.6% | Makefile 7.4%
๐ŸŒ
Beauty and Joy of Computing
bjc.edc.org โ€บ Jan2017 โ€บ bjc-r โ€บ cur โ€บ programming โ€บ old-labs โ€บ python โ€บ 2D_lists.html
2D Lists in Python
All of the previously mentioned list functions still operate on 2D lists: >>> cart[0][2] = "cabbage" >>> cart [ ["kale", "spinach", "cabbage"], ["olives", "tomatoes", "avocado"]] Now that you have some experience with lists in Python, try writing a function that takes a list of lists (2D) and returns all the items of each list concatenated together into one new list as shown below: >>> flatten([["a", "b"],["c", "d", "e"], ["f"]]) ["a", "b", "c", "d", "e", "f"] To test this function enter: python3 PythonLab2.py 2
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ 2d array ( list ) in python
r/learnpython on Reddit: 2D array ( list ) in Python
March 3, 2018 -

Hello, I created a 2D array ( list) in 2 different ways. For some reason I am getting different answers when I run a recursive program using these 2 lists: Which is the correct Python way to do it, I am getting incorrect answers using the first method, although the dimensions of the 2 arrays are absolutely the same

 First way:
 m = [[None]*(len(denoms))]*(n+1)

 Second way:
 m = [None] * (n+1)
 for row in range(n+1):
      m[row] = [None] * len(denoms)
๐ŸŒ
Oreate AI
oreateai.com โ€บ blog โ€บ understanding-2d-arrays-in-python-a-practical-guide โ€บ 92540c977547471c93a37af7f7204ada
Understanding 2D Arrays in Python: A Practical Guide - Oreate AI Blog
January 21, 2026 - To define a 2D array in Python using lists (since native multi-dimensional arrays aren't directly supported), we typically employ nested lists.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_dsa_lists.asp
Python Lists and Arrays
In Python, lists are the built-in data structure that serves as a dynamic array.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ appending-to-2d-list-in-python
Appending to 2D List in Python - GeeksforGeeks
July 23, 2025 - A 2D list in Python is a list of lists where each sublist can hold elements. Appending to a 2D list involves adding either a new sublist or elements to an existing sublist.
๐ŸŒ
Csuk
coder.csuk.io โ€บ coder_course_page โ€บ 2-dimensional-lists
2 Dimensional Lists โ€“ CSUK:Coder
A 2D list is essentially a list of lists, allowing you to organise data in rows and columns, much like a table or spreadsheet. In other programming languages, a similar concept is called a 2D array, where data is stored in a grid of rows and columns. In Python, although we donโ€™t have traditional ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_lists.asp
Python Lists
List is a collection which is ordered and changeable. Allows duplicate members. Tuple is a collection which is ordered and unchangeable. Allows duplicate members. Set is a collection which is unordered, unchangeable*, and unindexed.
๐ŸŒ
Guru99
guru99.com โ€บ home โ€บ python โ€บ python 2d arrays: two-dimensional list examples
Python 2D Arrays: Two-Dimensional List Examples
August 12, 2024 - We can create a two-dimensional array(list) with rows and columns. ... #creare 2D array with 4 rows and 5 columns array=[[23,45,43,23,45],[45,67,54,32,45],[89,90,87,65,44],[23,45,67,32,10]] #display print(array) #get the first row print(array[0]) #get the third row print(array[2]) #get the first row third element print(array[0][2]) #get the third row forth element print(array[2][3])
๐ŸŒ
Medium
medium.com โ€บ @zeebrockeraa โ€บ create-and-use-python-2d-list-169e22244ff3
Create And Use Python 2D List
July 8, 2023 - Python 2D list is a very powerful and useful. In this concept, weโ€™ve a Python list and the items of that list are also lists. It looks like a matrix.
๐ŸŒ
Python Pool
pythonpool.com โ€บ home โ€บ blog โ€บ python 2d list: from basic to advance
Python 2d List: From Basic to Advance - Python Pool
January 1, 2024 - The list is one of the most useful data-type in python. We can add values of all types like integers, string, float in a single list. List initialization can be done using square brackets []. Below is an example of a 1d list and 2d list. As we cannot use 1d list in every use case so python 2d list is used.
๐ŸŒ
Processing
py.processing.org โ€บ tutorials โ€บ 2dlists
Two-Dimensional Lists \ Tutorials
Python Mode for Processing extends the Processing Development Environment with the Python programming language.