Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The Filter Function
Search
Eloy Zuniga Jr.
May 15, 2018
Programming
0
73
The Filter Function
Basic understanding of the `filter` function.
Eloy Zuniga Jr.
May 15, 2018
Tweet
Share
More Decks by Eloy Zuniga Jr.
See All by Eloy Zuniga Jr.
The `max` function
eloy
0
60
The Command Line Interface
eloy
2
490
Python Decorators
eloy
8
630
Other Decks in Programming
See All in Programming
CSC509 Lecture 14
javiergs
PRO
0
220
Go コードベースの構成と AI コンテキスト定義
andpad
0
120
宅宅自以為的浪漫:跟 AI 一起為自己辦的研討會寫一個售票系統
eddie
0
490
ハイパーメディア駆動アプリケーションとIslandアーキテクチャ: htmxによるWebアプリケーション開発と動的UIの局所的適用
nowaki28
0
390
【Streamlit x Snowflake】データ基盤からアプリ開発・AI活用まで、すべてをSnowflake内で実現
ayumu_yamaguchi
1
120
S3 VectorsとStrands Agentsを利用したAgentic RAGシステムの構築
tosuri13
6
300
Microservices Platforms: When Team Topologies Meets Microservices Patterns
cer
PRO
1
1k
AIコーディングエージェント(Manus)
kondai24
0
160
20 years of Symfony, what's next?
fabpot
2
350
組み合わせ爆発にのまれない - 責務分割 x テスト
halhorn
1
140
Building AI Agents with TypeScript #TSKaigiHokuriku
izumin5210
6
1.3k
React Native New Architecture 移行実践報告
taminif
1
150
Featured
See All Featured
Producing Creativity
orderedlist
PRO
348
40k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Designing for humans not robots
tammielis
254
26k
4 Signs Your Business is Dying
shpigford
186
22k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
700
Optimizing for Happiness
mojombo
379
70k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.4k
The Cost Of JavaScript in 2023
addyosmani
55
9.3k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.8k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.5k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.8k
How to Ace a Technical Interview
jacobian
280
24k
Transcript
Handle Nonetype objects # Remove Nonetypes before using Max L
= [None, None, None] max([i for i in L if is not None], default=None) @eloy · python 3.6 · 2018 1/14
Using the filter function # Remove Nonetypes before using Max
max(filter(None, L), default=None) @eloy · python 3.6 · 2018 2/14
filter() Keep item if 'True'
Filter function # Takes a function and an iterable filter(<function>,
<iterable>) @eloy · python 3.6 · 2018 4/14
Let's try an example # Anything greater than 2 shall
pass def greater_than_2(item): """Assume item is integer.""" return item > 2 items = filter(greater_than_2, [1, 2, 3, 4]) @eloy · python 3.6 · 2018 5/14
Using the filter function # Remove Nonetypes before using Max
max(filter(None, L), default=None) @eloy · python 3.6 · 2018 6/14
@eloy · python 3.6 · 2018 7/14
Identity function # If NO function is passed, then we
use the "Identity function" filter(None, iterable) # Identity function = Is this Truthy or Falsey? truthy_items = [True, object, 'a', '0', 1, 2, -1] falsey_items = [False, None, '', "", 0] @eloy · python 3.6 · 2018 8/14
Testing identity function # Everything makes it through the filter
everything = filter(None, [True, object, 'a', 1]) # Nothing makes it through the filter nothing = filter(None, [False, None, '', "", 0]) @eloy · python 3.6 · 2018 9/14
Lets make a None function # Anything greater than 2
shall pass def fake_none(item): """Test truthiness.""" return bool(item) items = filter(fake_none, [1, 2, 3, 4]) @eloy · python 3.6 · 2018 10/14
Filter returns an iterable iterable = filter(None, truthy_items) @eloy ·
python 3.6 · 2018 11/14
Still an iterable iterable = list(filter(None, truthy_items)) @eloy · python
3.6 · 2018 12/14
Technically an iterator iterator = filter(None, truthy_items) @eloy · python
3.6 · 2018 13/14
Do you know the difference? 4 iterable 4 lazy iterable
4 iterator 4 range We'll talk about this next month :D @eloy · python 3.6 · 2018 14/14