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 `max` function
Search
Eloy Zuniga Jr.
April 17, 2018
Programming
0
60
The `max` function
Using the `max` function in python 3.6. Some caveats to watch out for.
Eloy Zuniga Jr.
April 17, 2018
Tweet
Share
More Decks by Eloy Zuniga Jr.
See All by Eloy Zuniga Jr.
The Filter Function
eloy
0
76
The Command Line Interface
eloy
2
490
Python Decorators
eloy
8
640
Other Decks in Programming
See All in Programming
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
180
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
120
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
170
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
dchart: charts from deck markup
ajstarks
3
990
Oxlintはいいぞ
yug1224
5
1.3k
FOSDEM 2026: STUNMESH-go: Building P2P WireGuard Mesh Without Self-Hosted Infrastructure
tjjh89017
0
150
AIと一緒にレガシーに向き合ってみた
nyafunta9858
0
170
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.8k
組織で育むオブザーバビリティ
ryota_hnk
0
170
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
400
AIエージェントのキホンから学ぶ「エージェンティックコーディング」実践入門
masahiro_nishimi
3
300
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Code Reviewing Like a Champion
maltzj
527
40k
Statistics for Hackers
jakevdp
799
230k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
1
1.3k
Paper Plane (Part 1)
katiecoart
PRO
0
4k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
66
36k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
200
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
63
Exploring anti-patterns in Rails
aemeredith
2
250
Reality Check: Gamification 10 Years Later
codingconduct
0
2k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
300
エンジニアに許された特別な時間の終わり
watany
106
230k
Transcript
max() caveats to consider
Max function # Assume `L` is a list of datetimes,
Nonetypes L = get_dates() max(L) # returns biggest item @eloy · python 3.6 · 2018 2/11
Original code component_times = max( rr_time, spo2_time, o2device_time, t_time, sbp_time,
hr_time) @eloy · python 3.6 · 2018 3/11
Empty sequence # Can we get a max item from
an empty sequence? max([]) @eloy · python 3.6 · 2018 4/11
Handle TypeError # Lets handle the `TypeError` try: max([]) except
TypeError: pass # Lets write less and make it more readable max([], default=None) @eloy · python 3.6 · 2018 5/11
None list # Can we get a max item from
a list of Nonetypes? L = [None, None] max(L) @eloy · python 3.6 · 2018 6/11
Handle ValueError # Lets handle the `ValueError` L = [None,
None] try: max(L) except ValueError: pass # What if `L` had both datetimes and Nonetype values? L = L + get_dates() @eloy · python 3.6 · 2018 7/11
Remove None items # Remove Nonetypes before using Max max([i
for i in L if is not None]) @eloy · python 3.6 · 2018 8/11
Does this work? # Remove Nonetypes before using Max L
= [None, None, None] max([i for i in L if is not None]) @eloy · python 3.6 · 2018 9/11
With default param # 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 10/11
Filter # Remove Nonetypes before using Max max(filter(None, L), default=None)
@eloy · python 3.6 · 2018 11/11