title: Getting index with list comprehension in a list in Python
body: <p>Here are two fonctions which (I thought) should do the same thing but actually do not.</p>
  
  <p>It seems that with the list comprehension, the index taken is the first that could correspond, so when you have the same value at different index, there is an ambiguity. </p>
  
  <p>Is there a way to modify the list comprehension in <code>filter2</code> so get the same result as in <code>filter1</code> ? </p>
  
  <pre><code>  L = [98.75011926342906,
   97.8178200008178,
   98.6138182016438,
   98.55520874507613,
   98.25262038791283,
   98.75011926342906,
   99.06770073738875,
   98.66970163697574,
   98.56611283001895,
   98.47751713985852, 
   98.66970163697574,
   97.8178200008178]
  
  
  def filter1(L, threshold=98.7):
      items = []
      for i in range(len(L)):
          if L[i] &lt; threshold:
              items.append(i)
      return items
  
  def filter2(L, threshold=98.7):
      items = [L.index(x) for x in L if  x &lt;= threshold]
      return items
  
  print filter1(L)
  &gt;&gt;&gt; [1, 2, 3, 4, 7, 8, 9, 10, 11]
  print filter2(L)
  &gt;&gt;&gt; [1, 2, 3, 4, 7, 8, 9, 7, 1]
  </code></pre>