Try this:

def index_2d(myList, v):
    for i, x in enumerate(myList):
        if v in x:
            return (i, x.index(v))

Usage:

>>> index_2d(myList, 3)
(1, 0)
Answer from Mark Byers on Stack Overflow
Discussions

arrays - How to get the full index of an object in a 2D list (Python) - Stack Overflow
How do I get the full index of obj in the 2D array. More on stackoverflow.com
🌐 stackoverflow.com
Help finding the index of a given value within a 2D array
Numpy is a great and powerful tool, but this is not one of the things it's good at. It would be much better for you to store the player's actual position, rather than searching for the player in a map. But if you really really want to: the function you want is np.argwhere. More on reddit.com
🌐 r/learnpython
3
1
November 13, 2022
python - using index() on multidimensional lists - Stack Overflow
For a one dimensional list, the index of an item is found as follows: a_list = ['a', 'b', 'new', 'mpilgrim', 'new'] a_list.index('mpilgrim') What is the equivalent for a 2 or n dimensional list?... 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
🌐
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.
🌐
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
🌐
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.
🌐
Beauty and Joy of Computing
bjc.edc.org › Jan2017 › bjc-r › cur › programming › old-labs › python › 2D_lists.html
2D Lists in Python
The first index returns the internal list, and the second index then looks into that retrieved list. 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 ...
🌐
Quora
quora.com › How-do-I-return-the-index-of-an-element-in-a-2D-array-in-Python
How to return the index of an element in a 2D array in Python - Quora
Answer (1 of 2): You don’t return the index - your code needs to keep track of where the elements are. If you are asking how do you search a 2D array - the only way is something like this: [code]def find_all(matrix, element): """Iterate through all row, column indexes in a 2D Matrix where ...
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 70299386 › how-to-get-the-full-index-of-an-object-in-a-2d-list-python
arrays - How to get the full index of an object in a 2D list (Python) - Stack Overflow
Copya = [[1,2,3], [4,5,6], [7,8,9]] # element that you want to find b = 2 for i,x in enumerate(a): if b in x: index_2d = (i, x.index(b)) ... Sign up to request clarification or add additional context in comments.
🌐
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?

🌐
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.
🌐
Processing
py.processing.org › tutorials › 2dlists
Two-Dimensional Lists \ Tutorials
Python Mode for Processing extends the Processing Development Environment with the Python programming language.
🌐
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].
🌐
Codecademy
codecademy.com › learn › introduction-to-python-for-finance › modules › learn-python3-lists › cheatsheet
Introduction to Python: Lists Cheatsheet | Codecademy
In order to access elements in a 2D list, an index for the sublist and the index for the element of the sublist both need to be provided. The format for this is list[sublist_index][element_in_sublist_index]. ... The .remove() method in Python ...
🌐
Du
cs.du.edu › ~intropython › intro-to-programming › 2Dlist_define.html
Defining 2D lists - Introduction to Programming
The first index gives the row and the second index gives the column. ... # Create an empty list temperature = [] # Four rows: for row in range(4): # Create an empty sub-list new_row = [] # Fill the row with three 0's for column in range(3): new_row.append(0) # Put the newly-created row into ...
🌐
Guru99
guru99.com › home › python › python 2d arrays: two-dimensional list examples
Python 2D Arrays: Two-Dimensional List Examples
July 10, 2026 - The index of the array starts with 0 and ends with a size of array minus 1. We can create ‘n’ number of arrays in an array. In the above image, we can see that an index uniquely identifies each array element.
🌐
Stack Overflow
stackoverflow.com › questions › 46536640 › 2-d-list-and-indexing
python - 2-D List and Indexing - Stack Overflow
def passenger_baggage(p, b): '''Print the weight of the bag b for passenger p.''' m = [[ 45,35,52,75],[25,30,65], [50,43,32,22,]] try: print('bag #{}, for passenger #{} weighs {} lb'.format(b, p, m[p][b]) except IndexError: print('Passenger #{} either doesn't exist or has no bag #{}.format(p,b)) ... Sign up to request clarification or add additional context in comments. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Claude solved this functional minimization problem over 2D probability distributions for us; how difficult was it?