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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Eloy Zuniga Jr.
May 15, 2018
Programming
87
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
The Filter Function
Basic understanding of the `filter` function.
Eloy Zuniga Jr.
May 15, 2018
More Decks by Eloy Zuniga Jr.
See All by Eloy Zuniga Jr.
The `max` function
eloy
0
69
The Command Line Interface
eloy
2
510
Python Decorators
eloy
8
640
Other Decks in Programming
See All in Programming
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
710
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.6k
AIチームを指揮するOSS「TAKT」活用術 / How to Use “TAKT,” an OSS Tool for Orchestrating AI Teams
nrslib
6
880
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
110
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
2
660
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
120
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
150
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
2
1.3k
Webフレームワークの ベンチマークについて
yusukebe
0
160
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
220
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
330
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
530
Featured
See All Featured
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
380
The Art of Programming - Codeland 2020
erikaheidi
57
14k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.1k
Site-Speed That Sticks
csswizardry
13
1.2k
The Language of Interfaces
destraynor
162
27k
How STYLIGHT went responsive
nonsquared
100
6.2k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.4k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
1.1k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.6k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
220
So, you think you're a good person
axbom
PRO
2
2.1k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.4k
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