Functional Programming in Python [pdf]
oreilly.com
Functional Programming in Python [pdf]
1–10 of 62 posts
Re: Functional Programming in Python [pdf]
#2"Python Bridge, officially known as High Bridge, is a bridge that spans the canal between Sporenburg and Borneo Island in Eastern Docklands, Amsterdam. It was built in 2001 and won the International Footbridge Award in 2002. The bright red bridge spans 90 meters and was designed by Adriaan Geuze of the architectural firm West 8"
Coincidentally, Amsterdam can be considered the birthplace of Python, where Guido used to work at the Center for Mathematics and Computer Science (CWI).
And now for some obligatory functional python. Run with
python lambda.py 2>&1 | head -c 200
to avoid filling your screen with exhausted recursion depth.
Notice any pattern in the output? import sys
def c(j,t):
sys.stdout.write(j('.')('P'))
return t
(lambda z:lambda y:z(z(y(lambda p:lambda n:(lambda s:lambda z:z(lambda x:
lambda y:y)(lambda d:p(s)(y(s))(d)))(lambda x:lambda a:lambda s:lambda p:
p(a)(lambda y:s(n(x))(y))))(lambda c:lambda a:lambda s:z(lambda y:s(c)(y)
))))(y(lambda p:lambda b:lambda t:t(c(b,p)))))(lambda s:lambda p:p(lambda
x:lambda y:x)(s))(lambda f:(lambda q:q(q))(lambda x:f(lambda y:x(x)(y))))Re: Functional Programming in Python [pdf]
#3 dict([n, 2 ** n] for n in range(5))
But they pointed out an actual "dict comprehension" that I didn't even realize existed: { n: n ** 2 for n in range(5) }
And there is a similar "set comprehension": { n ** 2 for n in range(5) }
Always amazes me how you can use Python for so many years and still encounter new features in the language.Re: Functional Programming in Python [pdf]
#4Re: Functional Programming in Python [pdf]
#5Even knowing a lot about FP, I still found this worth skimming for the esoteric Python syntax. When it comes to constructing dictionaries with list comprehensions, I would always do something like this: dict([n, 2 ** n] for n in range(5)) But they pointed out an actual "dict comprehension" that I didn't even realize existed: { n: n ** 2 for n in range(5) } And there is a similar "set comprehension": { n ** 2 for n in…
Re: Functional Programming in Python [pdf]
#6Even knowing a lot about FP, I still found this worth skimming for the esoteric Python syntax. When it comes to constructing dictionaries with list comprehensions, I would always do something like this: dict([n, 2 ** n] for n in range(5)) But they pointed out an actual "dict comprehension" that I didn't even realize existed: { n: n ** 2 for n in range(5) } And there is a similar "set comprehension": { n ** 2 for n in…
a = (i for i in range(10) if i % 2 == 0)
print(list(a))
You can omit the parenthesis, and use them in calls which expect an iterable. b = max(i for i in range(0, 10) if i % 2 == 0)
print(b)Re: Functional Programming in Python [pdf]
#7Even knowing a lot about FP, I still found this worth skimming for the esoteric Python syntax. When it comes to constructing dictionaries with list comprehensions, I would always do something like this: dict([n, 2 ** n] for n in range(5)) But they pointed out an actual "dict comprehension" that I didn't even realize existed: { n: n ** 2 for n in range(5) } And there is a similar "set comprehension": { n ** 2 for n in…
This is part of the generalized comprehension syntax. You can also do lazy generator comprehensions. a = (i for i in range(10) if i % 2 == 0) print(list(a)) You can omit the parenthesis, and use them in calls which expect an iterable. b = max(i for i in range(0, 10) if i % 2 == 0) print(b)
With the dictionary comprehension you can just separate the key and value with a colon, which is more natural. It might just be sugar on top of a generator expression but it is definitely a special case, syntactically speaking.
Re: Functional Programming in Python [pdf]
#8 func(*args)
apply(func, args)
[func(a) for a in collection]
map(func, collection)
[a for a in collection if func(a)]
filter(func, collection)
I don't see why people use all of this special syntax.Re: Functional Programming in Python [pdf]
#9Hard to tell from a quick scan, but it appears to be slightly more informative than the classic document in the python docs: https://docs.python.org/dev/howto/functional.html
- http://www.ibm.com/developerworks/library/l-prog/
- http://kachayev.github.io/talks/uapycon2012/#/
- http://anandology.com/python-practice-book/functional-progra...
- http://maryrosecook.com/blog/post/a-practical-introduction-t...