Wednesday, October 28, 2009

Python built-in functions

http://docs.python.org/library/functions.html

I heard they're pretty fast

map - maybe better for parallelization purposes
---
>>> l=[1,2,3,4,5]
>>> def dbl(x):
return x*2

>>> map(dbl, l)
[2, 4, 6, 8, 10]

or just
[x*2 for x in l]

set
---
>>> set([1,1,2,2,3,3])
set([1,2,3])

http://stackoverflow.com/questions/672172/how-to-use-python-map-and-other-functional-tools

No comments: