Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Python's Functional Tools
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Julian Gindi
December 03, 2013
Programming
840
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Python's Functional Tools
Advanced Python Magic
Julian Gindi
December 03, 2013
Other Decks in Programming
See All in Programming
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
500
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.8k
吝嗇家のためのAI活用 / AI development for miser - ChatGPT + Issue Driven Development
tooppoo
0
180
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
2
830
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
190
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
840
えっ!!コードを読まずに開発を!?
hananouchi
0
170
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
460
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
スマートグラスで並列バイブコーディング
hyshu
0
290
コーディングルールの鮮度を保ちたい for SRE NEXT 2026 / keep-fresh-go-internal-conventions-sre-next-2026
handlename
0
140
LaravelLive Japan の裏方のすべて — 第188回 PHP勉強会@東京 (2026-06-24)
suguruooki
2
150
Featured
See All Featured
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
460
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
260
Bash Introduction
62gerente
615
220k
SEO for Brand Visibility & Recognition
aleyda
0
4.6k
WCS-LA-2024
lcolladotor
0
680
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.6k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
330
Deep Space Network (abreviated)
tonyrice
0
220
Building an army of robots
kneath
306
46k
Side Projects
sachag
455
43k
Building AI with AI
inesmontani
PRO
1
1.1k
Transcript
Functional Python Tools Advanced Python Magic
I’m Julian Gindi • Python developer at iStrategylabs (here) •
(small-time) Python core contributor • github.com/juliangindi • @JulianGindi • JulianGindi.com • lebowski.juliangindi.com
Python @isl • Django (content-heavy websites) • General scripting and
internal tools • Fabric (executing commands on our servers) • Salt (provisioning our servers)
Goals • Basic understanding of functional programming • Explain how
it can help you craft simple, yet powerful code • Show you a couple practical applications of the functional paradigm
Golden Circle
Functional Programming (What) • First class functions. Higher-order functions •
Pure functions • State • Immutable Data • Verbs instead of nouns
Python? • Not a functional language in a “pure” sense
• Multi paradigm language • Doesn't really matter - tools are still useful and awesome • Practical
Why? • Downright awesome • Programs are easier to understand
and debug • Often faster • Superior ability to deal with concurrency
How? • Time for some CODE!
>>> my_tuple = ('A', 'B', ‘C’) >>> len(my_tuple) 3 >>>
my_tuple.append('D') Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'tuple' object has no attribute 'append'
Practical Features (Core) • Closures • Lambda’s • Iterators, generators
• Partials • List Comprehension • Tuples • Built in functions (map, reduce, apply)
# List Comprehensions def square_list(items): new_list = [] new_list.append([x
* x for x in items]) return new_list ! print square_list([1,2,3]) ! >> [1, 4, 9]
# Closures ! def average_closure(a, b): def sum(): return a
+ b return sum() / 2 ! print average_closure(4, 4) ! >> 4
import operator ! # Lambdas ! def weird_average(func, data) :
return reduce(operator.add, map(func, data)) / len(data) ! print weird_average(lambda x: x * x , [1,2,3]) ! >> 4.66
# Generators ! def fibonacci() : prev, current = 0,1
while True : yield current prev, current = current, prev + current ! # Generator instantiation gen = fibonacci() ! # Generator usage for i in range(10) : print gen.next() ! >> 1 1 2 3 5 8 13 21 34 55
# PARTIALS ! from functools import partial ! def power(x,y):
return x ** y ! square = partial(power, y = 2) cube = partial(power, y = 3) ! assert (square(5), cube(7)) == (25, 343) ! ! !
How to get started • ‘import functools’ • Create a
simple program in a functional style • http://www.defmacro.org/ ramblings/fp.html - Functional programming for the rest of us • Execution in the Kingdom of Nouns