Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
The `max` function
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Eloy Zuniga Jr.
April 17, 2018
Programming
73
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
The `max` function
Using the `max` function in python 3.6. Some caveats to watch out for.
Eloy Zuniga Jr.
April 17, 2018
Transcript
11 slides
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
More Decks by Eloy Zuniga Jr.
See All by Eloy Zuniga Jr.
The Filter Function
eloy
0
120
The Command Line Interface
eloy
2
530
Python Decorators
eloy
8
650
Other Decks in Programming
See All in Programming
Enforcing Your Architecture with Unit Tests in the AI Era (Swift Connection X)
steliosf
PRO
1
190
SODA - FACT BOOK(JP)
sodainc
1
40k
imagewebp()の向こう側: WebPはなぜ JPEG・PNGより軽いのか
yuzneri
0
150
baseline으로 마이그레이션, 리팩토링 안전하게 맡기기
fornewid
1
1.1k
[Kotlin Fest 2026] eBPF Tracing for Kotlin
takehaya
1
400
SONY CISC-NEWS NWS-1750 + NWB-225 ハードウェアメンテとフレームバッファカラー対応 / KOF2026
tsutsui
0
140
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
330
protojson における文字化けの扱い
kazuki1023
0
460
AIコーディングをセッションで終わらせない: PHPライブラリ開発におけるコンテキスト承継設計
ickx
0
110
Engineering Biometric UX Across Android Versions | DroidKnights 2026
ryunen344
1
220
Proxmox x Talos Linux x Terraform で実現するなんかいい感じの Kubernetes クラスタ / A Sleek Kubernetes Cluster Powered by Proxmox, Talos Linux, and Terraform
nnaka2992
0
310
ビジネスロジックを堅牢に~Scala 3のドメインプリミティブ~
j5ik2o
0
230
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
57
15k
Git: the NoSQL Database
bkeepers
PRO
433
67k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
670
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
550
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
760
We Have a Design System, Now What?
morganepeng
55
8.4k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
1.1k
Writing Fast Ruby
sferik
630
63k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
2
560
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k