0

For example I have:

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

if I use

l.index(4)

it returns back 0

How do I get it to return back 0, 3, 5?

desiigner
  • 89
  • 1
  • 3
  • 10
  • https://stackoverflow.com/questions/6294179/how-to-find-all-occurrences-of-an-element-in-a-list – apoteet Nov 17 '17 at 01:51
  • 1
    Possible duplicate of [How to find all occurrences of an element in a list?](https://stackoverflow.com/questions/6294179/how-to-find-all-occurrences-of-an-element-in-a-list) – jhpratt Nov 17 '17 at 02:09

2 Answers2

0

Try this:

l = [4, 1 ,3, 4, 7 , 4]
index = [i for i, x in enumerate(l) if x == 4]
print(index)
Jesse
  • 1,814
  • 1
  • 21
  • 25
0
[x[0] for x in enumerate(l) if x[1] == 4]
Nish
  • 189
  • 2
  • 6