5 ответов
+ 4
Mohammad , when you can present us your attempt, we can help you with a solution.
Until then, I give you some hints:
- use a nested for loop for the outer and the inner list
- in the outer loop, also use an enumerator to get its index position
- in the inner loop. check if the value you are looking for is a member of the inner list
- if yes, get its index by using the index() method, print the positions you have as [ndx1][ndx2]
+ 1
Lothar For example i want to get position of 23 in this matrix:
[[14,17,11],[10,23,42],[20,13,71]]
+ 1
Mohammad
23 in your list will be: lst[1][1]
Nested list example showing index's:
[[0,1,2],[0,1,2],[0,1,2]]
+ 1
you can use numpy.where like this:
arr = np.array([[14,17,11],[10,23,42],[20,13,71]])
print(*zip(*np.where(arr == 23)))
# (1, 1)