Saturday, April 05, 2008

Python notes for myself

filter = [x for x in S if P(x)]
map = [F(x) for x in S]
reduce(+, L) = sum(L)
reduce(&&, L) = all(L)
reduce(||, L) = any(L)
reduce(*, L) = nothing yet :(

reduce() goes away in Python 3000, but the others remain, although list comprehension is generally faster than the inevitable lambda that gets used in filter/map/reduce.

And now back to your regularly scheduled blogging.

No comments: