wish list for python

Dave Kuhlman dkuhlman at rexx.com
Fri Oct 24 11:41:56 EDT 2003


Jim Newton wrote:

[snip]
 
>      x = for i in some-sequence:
> blah blah blah.

Python has "list comprehensions" for this.  Consider:

    >>> a = [-1,1,-2,2,-3,3]
    >>> a
    [-1, 1, -2, 2, -3, 3]
    >>> [x for x in a if x > 0]
    [1, 2, 3]
    >>> def f(x):
    ...   return x * 3
    ...
    >>> [f(x) for x in a if x > 0]
    [3, 6, 9]
    >>>

For more info see: ... Well, I searched but could not find any
documentation on list comprehensions.  I suppose that's the
problem with putting every feature anyone asks for into a
language.

At one time, we had a nice, understandable language that even I
could learn.  Sigh.

    "I used to love her"

    I used to wake up each morning, get my breakfast in bed.
    When I had some worries she would ease my aching head.
    Now she runs around, with every man in town.
    Still trying to take me for that same old clown.
    Because I used to love her.  But, it's all over now.

  -- The Animals

    Adde parvum parvo magnus acervus erit.
    [Add little to little and there will be a big pile.]

  -- Ovid, quoted from "The mythical man-month", Frederick Brooks,
Chapter 5, "The second-system effect"

I admit it.  I'm a little grouchy this morning.  My work on this
parser thing is not going so well.

OK.  One more search and I found some documentation -- See Tutorial,
"5.1.4 List Comprehensions":

http://www.python.org/doc/current/tut/node7.html#SECTION007140000000000000000

Dave

[snap, err, I mean snip]

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
dkuhlman at rexx.com




More information about the Python-list mailing list