Python: liste.index() - mehrere Positionen ausgeben?

1 Antwort

liste = [1, 2, 3, 4, 5, 3, 4, 3 , 2, 2, 4, 3, 1]
positionen = list(i for i in range(len(liste)) if liste[i] == 3)

... oder als Hilfsfunktion:

def pos_n(haystack, needle):
return list(i for i in range(len(haystack)) if haystack[i] == needle)