title: In Python, I can't get all the return values but the last, what mistake did I do here?
body: <p>This is my code. I'm trying to take an input from the user, put it in a list, then check every elements if it is less than 5 characters.</p>
  <p>It's supposed to print all the names under such condition but it only returns the last element that fits the condition.</p>
  <p>My code:</p>
  <pre><code>#function to check the length of the characters
  def test(names):
  for x in names:
      if len(x) &lt;= 5:
          print(x)
  return x
  
  #ask input from the user 
  names = input(&quot;Enter names: &quot;).split()
  
  #convert to a list
  lst = list(names)
  
  #container 
  viewList = test(names)
  
  #print names under 5 characters
  print(&quot;Names under five characters: &quot;, viewList)
  
  #just to test the elements in the list
  print(names)
  </code></pre>
  <p>The Output:</p>
  <pre><code>Enter names: kent monique jeff ban
  kent
  jeff
  ban
  Names under five characters:  ban
  ['kent', 'monique', 'jeff', 'ban']
  </code></pre>
  <p>As you can see, it only prints the last element. What mistake am I doing here?</p>