Answers for "find the index of an element in a 2d list python"

1

python get index of item in 2d list

myList = [[1, 2], [3, 4], [5, 6]]


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


print(index_2d(myList, 3))
# you get
# (1, 0)
Posted by: Guest on January-03-2021

Code answers related to "find the index of an element in a 2d list python"

Python Answers by Framework

Browse Popular Code Answers by Language