$30 off During Our Annual Pro Sale. View Details »
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
73
The Command Line Interface
eloy
2
490
Python Decorators
eloy
8
630
Other Decks in Programming
See All in Programming
ゲームの物理 剛体編
fadis
0
350
大規模Cloud Native環境におけるFalcoの運用
owlinux1000
0
130
俺流レスポンシブコーディング 2025
tak_dcxi
14
8.9k
Cell-Based Architecture
larchanjo
0
130
実は歴史的なアップデートだと思う AWS Interconnect - multicloud
maroon1st
0
210
AIの誤りが許されない業務システムにおいて“信頼されるAI” を目指す / building-trusted-ai-systems
yuya4
6
3.7k
モデル駆動設計をやってみようワークショップ開催報告(Modeling Forum2025) / model driven design workshop report
haru860
0
270
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
190
認証・認可の基本を学ぼう前編
kouyuume
0
250
Socio-Technical Evolution: Growing an Architecture and Its Organization for Fast Flow
cer
PRO
0
370
FluorTracer / RayTracingCamp11
kugimasa
0
240
20 years of Symfony, what's next?
fabpot
2
370
Featured
See All Featured
RailsConf 2023
tenderlove
30
1.3k
The Cost Of JavaScript in 2023
addyosmani
55
9.4k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
The Pragmatic Product Professional
lauravandoore
37
7.1k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
The Invisible Side of Design
smashingmag
302
51k
Raft: Consensus for Rubyists
vanstee
141
7.2k
Making the Leap to Tech Lead
cromwellryan
135
9.7k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
Navigating Team Friction
lara
191
16k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.2k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.3k
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