+ 1
How shows all the indexes "p" in exemple. - list = ["p", "i", "p", "e"]?
If i enter list.index("p") in output we see index [0], but we have two "p" in the variable list. Why i cant see second "p" index. ["p", "i", "p", "e"] [0] [2- i cant see... Why? List = ["p", "i", "p"!!!!!?, "e"] print(list.index("p")) Output [0]! Where is second index "p"?
2 odpowiedzi
+ 3
.index finds only the the index of the first occurrence
l = 'pipe'
print([index for (index, c) in enumerate(l) if c == 'p']) # [0, 2]
+ 2
Anna, Thanks!