lyst[:None]

Oren Tirosh oren-py-l at hishome.net
Fri May 23 11:37:32 EDT 2003


On Fri, May 23, 2003 at 04:48:01PM +0200, Jacek Generowicz wrote:
> Alex Martelli <aleaxit at yahoo.com> writes:
> 
> > > Is there a way of doing this on one line?
> > 
> > sys.maxint works.  You do have to have imported sys previously, normally,
> > but if you're keen to avoid that, and don't care for readability,
> > __import__('sys').maxint should be equivalent.
> 
> No, I wasn't wanting to be _that_ extreme. :-)
> 
> My main motivation was preferring to write
> 
>     [ 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]]

Oren





More information about the Python-list mailing list