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
77
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
62
The Command Line Interface
eloy
2
490
Python Decorators
eloy
8
640
Other Decks in Programming
See All in Programming
Claude Code Skill入門
mayahoney
0
420
maplibre-gl-layers - 地図に移動体たくさん表示したい
kekyo
PRO
0
450
Redox OS でのネームスペース管理と chroot の実現
isanethen
0
420
Java 21/25 Virtual Threads 소개
debop
0
260
new(1.26) ← これすき / kamakura.go #8
utgwkk
0
2.6k
存在論的プログラミング: 時間と存在を記述する
koriym
4
440
Pythonデータ分析コトハジメinFukuoka
kanan
0
100
Claude Codeログ基盤の構築
giginet
PRO
7
3.6k
Ruby and LLM Ecosystem 2nd
koic
1
1.3k
Codex CLIのSubagentsによる並列API実装 / Parallel API Implementation with Codex CLI Subagents
takatty
2
270
AHC061解説
shun_pi
0
420
Understanding Apache Lucene - More than just full-text search
spinscale
0
140
Featured
See All Featured
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
280
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
330
How STYLIGHT went responsive
nonsquared
100
6k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
980
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
150
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.1k
Art, The Web, and Tiny UX
lynnandtonic
304
21k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
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