List Comprehensions Enhancement
Hannah Schroeter
hannah at schlund.de
Tue Sep 14 14:53:09 EDT 1999
Hello!
In article <937299983snz at vision25.demon.co.uk>,
Phil Hunt <philh at vision25.demon.co.uk> wrote:
>[...]
>Or use a Smalltalk-like collect reserved word, e.g.:
>print [collect 3 * x for x in nums]
>print [collect (i,s) for i in nums, for s in strs]
Just to be sure, collect is NOT a reserved word in Smalltalk,
but about what "map" is in Python and most functional languages.
E.g.
#(1 2 3)
is an array constant.
#(1 2 3) collect: [:each | each * 2]
yields (2 4 6) as result.
The equivalent in Haskell would be
map (\each -> each * 2) [1,2,3]
or in Python
map (lambda each: each * 2, [1,2,3])
Regards, Hannah.
More information about the Python-list
mailing list