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
The Filter Function
Search
Eloy Zuniga Jr.
May 15, 2018
Programming
0
66
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
58
The Command Line Interface
eloy
2
490
Python Decorators
eloy
8
630
Other Decks in Programming
See All in Programming
MCPとデザインシステムに立脚したデザインと実装の融合
yukukotani
3
1.1k
Go言語での実装を通して学ぶLLMファインチューニングの仕組み / fukuokago22-llm-peft
monochromegane
0
110
Azure SRE Agentで運用は楽になるのか?
kkamegawa
0
1.2k
MCPで実現するAIエージェント駆動のNext.jsアプリデバッグ手法
nyatinte
7
1k
Honoアップデート 2025年夏
yusukebe
1
900
AIを活用し、今後に備えるための技術知識 / Basic Knowledge to Utilize AI
kishida
19
4.4k
Kiroで始めるAI-DLC
kaonash
2
520
「手軽で便利」に潜む罠。 Popover API を WCAG 2.2の視点で安全に使うには
taitotnk
0
390
testingを眺める
matumoto
1
130
AIコーディングAgentとの向き合い方
eycjur
0
250
レガシープロジェクトで最大限AIの恩恵を受けられるようClaude Codeを利用する
tk1351
4
1.6k
機能追加とリーダー業務の類似性
rinchoku
0
460
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
330
21k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
What's in a price? How to price your products and services
michaelherold
246
12k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
Speed Design
sergeychernyshev
32
1.1k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.9k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
48
9.7k
The Invisible Side of Design
smashingmag
301
51k
Optimizing for Happiness
mojombo
379
70k
How to train your dragon (web standard)
notwaldorf
96
6.2k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.5k
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