An array and nested list version:

In [163]: A=np.arange(12).reshape(3,4)
In [164]: Al = A.tolist()

For sliced indexing, a list comprehension (or mapping equivalent) works fine:

In [165]: A[:,1:3]
Out[165]: 
array([[ 1,  2],
       [ 5,  6],
       [ 9, 10]])
In [166]: [l[1:3] for l in Al]
Out[166]: [[1, 2], [5, 6], [9, 10]]

For advanced indexing, the list requires a further level of iteration:

In [167]: A[:,[0,2,3]]
Out[167]: 
array([[ 0,  2,  3],
       [ 4,  6,  7],
       [ 8, 10, 11]])

In [169]: [[l[i] for i in [0,2,3]] for l in Al]
Out[169]: [[0, 2, 3], [4, 6, 7], [8, 10, 11]]

Again there are various mapping alternatives.

In [171]: [operator.itemgetter(0,2,3)(l) for l in Al]
Out[171]: [(0, 2, 3), (4, 6, 7), (8, 10, 11)]

itemgetter uses tuple(obj[i] for i in items) to generate those tuples.

Curiously, itemgetter returns tuples for the list index, and lists for slices:

In [176]: [operator.itemgetter(slice(1,3))(l) for l in Al]
Out[176]: [[1, 2], [5, 6], [9, 10]]
Answer from hpaulj on Stack Overflow
🌐
Beauty and Joy of Computing
bjc.edc.org › March2019 › bjc-r › cur › programming › old-labs › python › 2D_lists.html
2D Lists in Python
A list within another list is called 2-Dimensional (2D). And just like in a 2D cartesian graph, retrieving an element requires two index values (essentially "the x and y position").
Discussions

Python: Return 2 ints for index in 2D lists given item - Stack Overflow
I've been tinkering in python this week and I got stuck on something. If I had a 2D list like this: ... How is myList.index(3) returning 1,0 in the first place? More on stackoverflow.com
🌐 stackoverflow.com
python - Indexing a 2D List with another List - Stack Overflow
However, I find that this syntax is quite clunky and doesn't sit well in a big block of code. It would also become worse with a higher dimensional list. My question: is there an easier way to do this index? ... Since you're working with a 2D-list, it might be a good idea to use numpy. More on stackoverflow.com
🌐 stackoverflow.com
[Python] 2D list indexing and slicing
I don't think you can just do it with slicing. I recommend creating a function for this. You can create a result list and append elements to it, use a list comprehension, or even use map with a lambda expression. def get_column(matrix, col): # Your code here More on reddit.com
🌐 r/learnprogramming
3
2
February 20, 2020
python - 2-D List and Indexing - Stack Overflow
Write a function passenger_baggage() that has two parameters: p and b, where p is the passenger number and b is the bag number. In your function, assign the following 2-D list to a variable as such... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-using-2d-arrays-lists-the-right-way
Using 2D arrays/lists in Python - GeeksforGeeks
Python creates only one inner list and one 0 object, not separate copies. This shared reference behavior is known as shallow copying (aliasing). If we assign the 0th index to another integer say 1, then a new integer object is created with the value of 1 and then the 0th index now points to this new int object as shown below · Similarly, when we create a 2d array as "arr = [[0]*cols]*rows" we are essentially extending the above analogy.
Published: December 20, 2025
🌐
Statistics Globe
statisticsglobe.com › home › python programming language for statistics & data science › get index of item in 2d list in python (2 examples)
Get Column & Row Index of Item in 2D List in Python (2 Examples)
May 4, 2023 - The inner loop also uses the same functions to return the index positions of the columns in the 2D list, ranging from 0 to 2. Remember, Python indexing starts from 0.
🌐
Carnegie Mellon University
cs.cmu.edu › ~15110-s22 › slides › week4-3-lists.pdf pdf
Lists and Methods 15-110 – Friday 02/11
When you loop over a 2D list and want to access every element, you need to use nested for loops. Often, the outer loop iterates over the indexes of the outer list (rows) and the inner loop iterates over ... This tells Python to call the built-in string function isdigit on the string s.
🌐
Du
cs.du.edu › ~intropython › intro-to-programming › 2Dlist_define.html
Defining 2D lists - Introduction to Programming
Rather than focusing on 2D lists as a list of lists, another perspective is to think of it as a rectangular grid, each position having a row position and a column position. So to indicate a specific element, you give two index values.
Find elsewhere
🌐
Profound Academy
profound.academy › python-introduction › 2d-lists-akMJGCqUglNeHMBStGJ6
2D lists • Introduction to Python
November 2, 2024 - The first index indicates the “row” we pick from the matrix, while the second index indicates the “column”. So, the syntax of accessing an element from a 2D list is two_d[row][column].
🌐
Dot Net Perls
dotnetperls.com › 2d-python
Python - 2D List Examples - Dot Net Perls
Detail The multiplication of the coordinates returns a single integer for a 2D point. Here We define get_element and set_element methods. We compute indexes based on an "x" and "y" coordinate pair. def get_element(elements, x, y): return elements[x + (y * 4)] def set_element(elements, x, y, value): elements[x + (y * 4)] = value # Create a list of 16 elements.
🌐
Processing
py.processing.org › tutorials › 2dlists
Two-Dimensional Lists \ Tutorials
Python Mode for Processing extends the Processing Development Environment with the Python programming language.
🌐
Snakify
snakify.org › two-dimensional lists (arrays)
Two-dimensional lists (arrays) - Learn Python 3 - Snakify
In this array there are n = 5 rows, m = 6 columns, and the element with row index i and column index j is calculated by the formula a[i][j] = i * j.
🌐
GeeksforGeeks
geeksforgeeks.org › python-using-2d-arrays-lists-the-right-way
Python | Using 2D arrays/lists the right way - GeeksforGeeks
This peculiar functioning is because Python uses shallow lists which we will try to understand. In method 1a, Python doesn't create 5 integer objects but creates only one integer object, and all the indices of the array arr point to the same int object as shown. If we assign the 0th index to another integer say 1, then a new integer object is created with the value of 1 and then the 0th index now points to this new int object as shown below · Similarly, when we create a 2d array as "arr = [[0]*cols]*rows" we are essentially extending the above analogy.
Published: June 20, 2024
🌐
GeeksforGeeks
geeksforgeeks.org › python › indexing-lists-of-lists-in-python
Indexing Lists Of Lists In Python - GeeksforGeeks
July 23, 2025 - Lists of lists, also known as nested lists or sometimes 2D lists, are powerful structures in Python for managing multi-dimensional data such as matrices or tables. Direct Indexing is the easiest way to access an element in a list of lists.
🌐
Guru99
guru99.com › home › python › python 2d arrays: two-dimensional list examples
Python 2D Arrays: Two-Dimensional List Examples
July 10, 2026 - The examples below show how to create, access, insert, update, delete, and size 2D arrays. 🧱 Structure: A 2D array is an array of arrays in rows and columns. 🔢 Indexing: Access an element with array[row][column]; indexes start at 0.
🌐
Brainly
brainly.com › computers and technology › high school › indexes of 2d lists are listed _rows_ first and then _columns_.
[FREE] Indexes of 2D lists are listed _rows_ first and then _columns_. - brainly.com
April 11, 2024 - In Python, the indexing of 2D lists follows a common convention where the first index corresponds to the row number and the second index corresponds to the column number.
🌐
Stack Overflow
stackoverflow.com › questions › 46536640 › 2-d-list-and-indexing
python - 2-D List and Indexing - Stack Overflow
The matrix or 2-D list m shows bag weights in pounds for three passengers. The first passenger has 4 bags, the second passenger has 3 bags and the third passenger has 4 bags. Your function will use a row and column index as discussed during the lecture to display passenger information as shown in Example, using format() string method
🌐
Reddit
reddit.com › r/learnpython › help finding the index of a given value within a 2d array
r/learnpython on Reddit: Help finding the index of a given value within a 2D array
November 13, 2022 -

Been messing around with numpy, trying to familiarize myself with it and seeing how I'd be able to utilize its arrays to store (very simple) map data for this text adventure game I've been working on. So far it seems like it'd be pretty darn useful, but I seem to have run into something of an issue.

My code is as follows (note: this is purposefully made with out a main class, because I am just trying to get the basic functionality down in my head before I incorporate it into my main program, and this is just easier for me):

# import numpy module as np
import numpy as np

# Establish the game map, a 3x3 grid of 0's
mainarray = np.array([[0, 0, 0],
                      [0, 0, 0],
                      [0, 0, 0]])

# Give feedback to make console easier to read
print(mainarray)
print("")
print("Placing player in center...")

# Place player on map (represented by a value of 1)
mainarray[1, 1] = 1

print(mainarray)

print("")
print("Locating player...")

# Attempt to find what the current index is of the value 1
print("")
print("Player is at index: ", np.where(mainarray == 1)[0][0])

In my head, I would like to eventually use this np.where() function (if I can) in one of the functions that moves my character. What I want to do is grab the current index of the "player" (represented by the number 1) and attempt to change that value to a 0, and change the value at an adjacent index to 1 (the tile that the player is moving to). Basically, I would like to use each index of the array as a sort of coordinate that I can take and use to move this "1" around the array, setting each index back to "0" after moving the "1", all based off user input.

Anyways, I am not getting any errors, however, the result that gets printed to the console is:

Player is at index:  1

Why is it just one number? It remains the same, even when I remove that second [0] in the last line. I don't fully understand how this function works, as this is the first time I've tried to use it, but since there are no errors, I have no clue what is going on.

Shouldn't I be receiving an index with two values, one for the column and one for the row? If not, how can I grab that as a result and use it in the way I described above? Is it even possible, or am I barking up the wrong tree with this function?

🌐
Quora
quora.com › How-do-you-access-a-two-dimensional-list-in-Python
How to access a two-dimensional list in Python - Quora
Answer (1 of 2): You use []s for indexing twice: That said, if you really want a matrix, i.e., a 2-D array, you should use NumPy: Lists are containers, whereas NumPy arrays are mathematical objects. If you’re doing math, use NumPy, but if you’re just holding stuff, use lists.