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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Julian Gindi
December 03, 2013
Programming
1
830
Python's Functional Tools
Advanced Python Magic
Julian Gindi
December 03, 2013
Tweet
Share
Other Decks in Programming
See All in Programming
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
680
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
190
組織で育むオブザーバビリティ
ryota_hnk
0
170
Smart Handoff/Pickup ガイド - Claude Code セッション管理
yukiigarashi
0
130
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
200
AtCoder Conference 2025
shindannin
0
1k
CSC307 Lecture 03
javiergs
PRO
1
490
ぼくの開発環境2026
yuzneri
0
110
Fragmented Architectures
denyspoltorak
0
150
Basic Architectures
denyspoltorak
0
660
AI時代の認知負荷との向き合い方
optfit
0
150
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
Featured
See All Featured
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.1k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
280
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
430
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
220
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
The Mindset for Success: Future Career Progression
greggifford
PRO
0
230
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
730
Testing 201, or: Great Expectations
jmmastey
46
8k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
450
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
210
Embracing the Ebb and Flow
colly
88
5k
The Limits of Empathy - UXLibs8
cassininazir
1
210
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