Suggestion for alternative to map/filter functions

Stephan Houben stephan at pcrm.win.tue.nl
Fri Apr 23 10:34:06 EDT 1999


"Evan Simpson" <evan at tokenexchange.com> writes:

> What language are we speaking of here?  I'm sure somebody here would be
> interested in a description of this mystery construct, if it's sufficiently
> elegant. Sorry, I find your post amusingly cryptic.

My guess would be that he's talking about list comprehension.
(Did I spell that last word correctly.)

That looks something like this (pseudo Haskell/Python alert):

  strlist = [str(i) | i <- intlist ]

,which is supposed to do the same thing as strlist = map(str,intlist).
To filter out all negative numbers:

  strlist = [str(i) | i <- intlist | i >= 0]

You see, mapping and filtering in one fellow swoop! Cool!
Sorts of, at least.

Greetings,

Stephan 




More information about the Python-list mailing list