lyst[:None]

Jacek Generowicz jacek.generowicz at cern.ch
Fri May 23 10:48:01 EDT 2003


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]

rather than

    lyst = [ foo(x) for x in bar]
    if limit:
        print list[:limit]
    else:
        print list

But thanks for reminding me that it's possible, anyway.




More information about the Python-list mailing list