functional programming with map()
ballabio at mac.com
Mon Feb 25 10:43:57 CET 2002
At 04:12 AM 2/25/02 +0000, Courageous wrote:
> >[x.f() for x in items]
>Yeah, whoever it was that decided this was the syntax
>for a list comprehension was just a plain genius. It's
>one of those linguistic thingies where you take one
>look at it, and you say, "of course".
It's from Haskell, I think, which in turn took it from plain old mathematics.
Haskell syntax is : [ f(x,y) | x <- items, y <- moreItems, x+y < 5 ]
Math notation is the same without brackets and with the "belongs to" symbol
(the one you get with $\in$ in TeX). Well, you might have : instead of |, too.
Of course Guido might have travelled back in time and suggested it so that
it was there for Python to borrow afterwards :)
More information about the Python-list