lyst[:None]
Jacek Generowicz
jacek.generowicz at cern.ch
Mon May 26 03:16:18 EDT 2003
Oren Tirosh <oren-py-l at hishome.net> writes:
> > [ foo(x) for x in bar][:limit]
>
> This makes redundant calls to foo. Everything after limit will be
> calculated and then thrown away. Try this:
>
> [foo(x) for x in bar:[limit]]
Doh! Thanks for pointing that out.
"Raymond Hettinger" <vze4rx4y at verizon.net> writes:
> In Python2.3, use itertools.islice():
> [foo(x) for x in islice(bar, limit)]
>
> The iterator is very fast and avoids making a copy
> of the whole sequence. To loop to the end of the
> sequence, set limit to None.
I really must find the time to have a good look at what 2.3 has
introduced. Thanks for the pointer.
More information about the Python-list
mailing list