title: Find all the values that meet the condition in Python
body: <p>I want to find a set of numbers that can meet certain conditions.
  For example, find a set of words that can exist in the dictionary:</p>
  <pre><code>testlist = &quot;I like sunny and I like cloudy&quot;
  testlist1 = testlist.split()
  dictionary = {'like': 'love'}
  </code></pre>
  <p>Obviously 1 and 5 can meet the requirements, but printing in different positions will display different results. If the position is on the left, only one number is displayed:</p>
  <pre><code>for i in range(len(testlist1)):
      if testlist1[i] in list(dictionary.keys()):
          print(i)
  print(i)
  </code></pre>
  <p>which is:</p>
  <pre><code>1
  5
  6
  </code></pre>
  <p>If I add a parameter, the result will be different:</p>
  <pre><code>for i in range(len(testlist1)):
      if testlist1[i] in list(dictionary.keys()):
          m = i
          print(m)
  print(m)
  </code></pre>
  <p>which is:</p>
  <pre><code>1
  5
  5
  </code></pre>
  <p>How can 1 and 5 be in a list?</p>
  <pre><code>['1', '5']
  </code></pre>
  <p>Thank you so much</p>