Python is faster than C

Raymond Hettinger python at rcn.com
Mon Apr 5 04:01:14 EDT 2004


> >>>> enumerate('abcdefgh')
>  <enumerate object at 0x401a102c:  (0, 'a') (1, 'b') (2, 'c') ...>
> >>>> list(_)
> > [(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd'), (4, 'e'), (5, 'f'), (6, 'g'),
> > (7, 'h'), (8, 'i'), (9, 'j'), (10, 'k'), (11, 'l'), (12, 'm'), (13,
> > 'n')]
 
[Carl Banks] 
> I thought this myself, but what if the iterator is computationally
> intensive?

Since no more than three items are displayed, the interactive prompt
will still handle this much better than something like range(10000000)
which takes a while to compute and display.

Besides, everything you do in Python pays a little performance penalty
just to make sure you can break out of computationally intensive
tasks.

For me, these almost never arise at the interactive prompt.

Likewise, I program in a less hostile world than Andrew Dalke who has
to contend with pandora's box iterators which ruin the lives of mortal
men who think they can call .next() with impunity ;-)


Raymond Hettinger



More information about the Python-list mailing list