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
Apache Iceberg V3 and migration to V3
tomtanaka
0
110
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
170
AtCoder Conference 2025
shindannin
0
1k
Fluid Templating in TYPO3 14
s2b
0
110
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
170
高速開発のためのコード整理術
sutetotanuki
1
340
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.2k
TerraformとStrands AgentsでAmazon Bedrock AgentCoreのSSO認証付きエージェントを量産しよう!
neruneruo
4
2.6k
Data-Centric Kaggle
isax1015
2
710
カスタマーサクセス業務を変革したヘルススコアの実現と学び
_hummer0724
0
430
Unicodeどうしてる? PHPから見たUnicode対応と他言語での対応についてのお伺い
youkidearitai
PRO
0
990
CSC307 Lecture 03
javiergs
PRO
1
480
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Git: the NoSQL Database
bkeepers
PRO
432
66k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
210
The Mindset for Success: Future Career Progression
greggifford
PRO
0
220
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
0
260
Code Reviewing Like a Champion
maltzj
527
40k
Speed Design
sergeychernyshev
33
1.5k
For a Future-Friendly Web
brad_frost
181
10k
We Are The Robots
honzajavorek
0
140
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
What does AI have to do with Human Rights?
axbom
PRO
0
1.9k
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