Why does map return a map object instead of a list in Python 3?
<p>I am interested in understanding the <a href="http://stackoverflow.com/questions/1303347/getting-a-map-to-return-a-list-in-python-3-x">new language design of Python 3.x</a>.</p>

<p>I do enjoy, in Python 2.7, the function <code>map</code>:</p>

<pre><code>Python 2.7.12
In[2]: map(lambda x: x+1, [1,2,3])
Out[2]: [2, 3, 4]
</code></pre>

<p>However, in Python 3.x things have changed:</p>

<pre><code>Python 3.5.1
In[2]: map(lambda x: x+1, [1,2,3])
Out[2]: &lt;map at 0x4218390&gt;
</code></pre>

<p>I understand the how, but I could not find a reference to the why. Why did the language designers make this choice, which, in my opinion, introduces a great deal of pain. Was this to arm-wrestle developers in sticking to list comprehensions?</p>

<p>IMO, list can be naturally thought as <a href="http://learnyouahaskell.com/functors-applicative-functors-and-monoids" rel="nofollow">Functors</a>; and I have been somehow been thought to think in this way:</p>

<pre><code>fmap :: (a -&gt; b) -&gt; f a -&gt; f b
</code></pre>

<p>In Python 3, many functions (not just <code>map</code> but <code>zip</code>, <code>range</code> and others) return an iterator rather than the full list. This puts an emphasis on a <em>lazy</em> approach, where each item is generated sequentially on the fly until the iterator is exhausted, so that an entire list does not need to be held in memory unnecessarily. Iterators are not always suitable, for example if you need to access the entire list at once or particular list indexes.</p>

<p>In your example, if you had a much more intensive calculation like <code>map(lambda x: x+1, range(large_number))</code> (the equivalent would be <code>xrange</code> in Python 2) then it would make little sense to generate a list immediately rather than process each item of the iterator one by one. However, in this case, and many others, a generator expression would suffice and be arguable more readable, like <code>(x+1 for x in range(large_number))</code>.</p>

<p>Note that for <code>map()</code>/<code>list(map)</code> in Python 3 is not quite equivalent to <code>iter(map())</code>/<code>map()</code> in Python 2 as explained in answers to this <a href="http://stackoverflow.com/questions/12015521/python-3-vs-python-2-map-behavior">question</a>.</p>

python python-3.x