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
AtCoder Conference 2025
shindannin
0
1k
16年目のピクシブ百科事典を支える最新の技術基盤 / The Modern Tech Stack Powering Pixiv Encyclopedia in its 16th Year
ahuglajbclajep
5
990
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
180
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
680
CSC307 Lecture 05
javiergs
PRO
0
490
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
190
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
110
Vibe Coding - AI 驅動的軟體開發
mickyp100
0
170
dchart: charts from deck markup
ajstarks
3
990
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
250
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
20
6.7k
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
190
Featured
See All Featured
The Spectacular Lies of Maps
axbom
PRO
1
520
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.1k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
120
GraphQLの誤解/rethinking-graphql
sonatard
74
11k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
90
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
640
How GitHub (no longer) Works
holman
316
140k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
72
Being A Developer After 40
akosma
91
590k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
170
Facilitating Awesome Meetings
lara
57
6.7k
A Modern Web Designer's Workflow
chriscoyier
698
190k
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