<div class="gmail_quote">On 3 June 2011 19:05, Thomas Jollans <span dir="ltr"><<a href="mailto:t@jollybox.de">t@jollybox.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div style="font-family:'Droid Sans Mono';font-size:10pt;font-weight:400;font-style:normal">
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">On Friday 03 June 2011, it occurred to Tim Delaney to exclaim:</p><div class="im">
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> Probably the biggest savings are list creating and jumping between C- and</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> Python-functions during the map call. The lambda is a Python function,</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> which are notoriously slow to use from within map() in comparison to</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> keeping it all as C-level. Creating intermediate lists is totally</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> unnecessary and obviously a waste of time. You're actually creating 3</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> intermediate lists - one with map(), one with zip() and one with range()</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">> (the third only if this is Python 2.x code, not 3.x).</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br></p>
</div><p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">Actually, in Python 3, map and zip also return iterators, so I would expect the two versions to be almost the same speed in Python 3. The Python function call is of course still slow.</p>
</div></blockquote><div><br></div><div>You are of course right ... that would be a d'oh! moment for me ;)</div><div><br></div><div>Tim Delaney </div></div>