+ 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"?

5th May 2019, 7:12 PM
Sergey Kramer
Sergey Kramer - avatar
2 Respuestas
+ 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]
5th May 2019, 7:22 PM
Anna
Anna - avatar
+ 2
Anna, Thanks!
5th May 2019, 7:31 PM
Sergey Kramer
Sergey Kramer - avatar