title: Why does the map object in Python 3 need to be cast to a list to function with comprehension?
body: <p>This question comes from a hackerrank question from basic data types. When I run</p>
  
  <pre><code>max(map(int, range(5)))
  </code></pre>
  
  <p>I get the right output of 4, however when I do</p>
  
  <pre><code>if __name__ == '__main__':
      n = int(input()) #this line seems irrelevant to my question, but it was present in the original question so I have included it here for completeness
      arr = map(int, input().split())
      print(max([x for x in arr if x &lt; max(arr)]))
  </code></pre>
  
  <p>and give input</p>
  
  <pre><code>5
  2 3 6 6 5
  </code></pre>
  
  <p>the result is 2. However if I first cast the map object to a list I get the correct answer of 5. This is further bewildering as when I replace the print argument with</p>
  
  <pre><code>print(max(arr))
  </code></pre>
  
  <p>it gives the correct answer of 6, so clearly max works, but I'm guessing something in the list comprehension breaks on map objects for some reason. This is especially supported by the fact that if I do</p>
  
  <pre><code>print([x for x in arr if x &lt; max(arr)])
  </code></pre>
  
  <p>I get 2. More testing with other less ordered lists shows that the last statement seems to always return list(arr)[0], so ultimately I expect the issue is with the list comprehension on the map objects. So ultimately what I'd like to know is</p>
  
  <ul>
  <li>How does Python 3.5.x deal with map objects and list comprehensions which is causing the failure?</li>
  <li>Is there any way to successfully process the map object in a straightforward way with a comprehension that does not involve casting?</li>
  </ul>