how to get second value in 2 d list python code example
Example 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)
Example 2: print 2d list in one line
import itertools
arr = [[1, 2, 3], [3, 4, 5]]
res = list(itertools.chain(*arr))
print(" ".join(map(str, res)))
1 2 3 3 4 5