string bug/oddity?

Alex Martelli aleaxit at yahoo.com
Mon Aug 13 03:00:16 EDT 2001


"Aahz Maruch" <aahz at panix.com> wrote in message
news:9l7k5i$5eh$1 at panix2.panix.com...
> In article <3B77150B.9F8FC079 at engcorp.com>,
> Peter Hansen  <peter at engcorp.com> wrote:
> >
> >Anything wrong with this, simpler, approach?
> >
> >>>> for x in a.keys():
> >...     print '%s%s' % (x, a[x])
>
> Even simpler and faster:
>
> for x,y in a.items():
>     print '%s%s' % (x,y)

Simpler, yes.  Not necessarily faster, and I was surprised when I
actually measured iteration on .keys vs iteration on .items: the
allocation/building of the N pairs may apparently take longer
than the N [] indexing operations.  Measure the two alternatives
if you do need top speed at this point...


Alex






More information about the Python-list mailing list