2017-11-17 5 views
0

나는이 :같은 값의 다른 인덱스를 찾는 방법은 무엇입니까? 예를 들어

l = [4, 1 ,3, 4, 7 , 4] 

내가

l.index(4) 

을 사용하여 그것을 내가 다시 0, 3, 5를 반환받을 수 있나요 어떻게 다시 0

반환하는 경우?

+0

https://stackoverflow.com/questions/6294179/how-to-find-all-occurrences-of-an-element-in-a-list – dementis

+1

[목록에있는 요소의 모든 항목을 찾는 방법?] (https://stackoverflow.com/questions/6294179/how-to-find-all-occurrences-of-an-element-in-a-) 명부) – jhpratt

답변

0

이 시도 :

l = [4, 1 ,3, 4, 7 , 4] 
index = [i for i, x in enumerate(l) if x == 4] 
print(index) 
0
[x[0] for x in enumerate(l) if x[1] == 4]