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
CSC307 Lecture 08
javiergs
PRO
0
670
AIと一緒にレガシーに向き合ってみた
nyafunta9858
0
190
CSC307 Lecture 03
javiergs
PRO
1
490
CSC307 Lecture 09
javiergs
PRO
1
830
OSSとなったswift-buildで Xcodeのビルドを差し替えられるため 自分でXcodeを直せる時代になっている ダイアモンド問題編
yimajo
3
610
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
530
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
190
Honoを使ったリモートMCPサーバでAIツールとの連携を加速させる!
tosuri13
1
170
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
180
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
640
SourceGeneratorのススメ
htkym
0
190
Fragmented Architectures
denyspoltorak
0
150
Featured
See All Featured
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
72
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
231
22k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
55
AI: The stuff that nobody shows you
jnunemaker
PRO
2
250
A Modern Web Designer's Workflow
chriscoyier
698
190k
My Coaching Mixtape
mlcsv
0
47
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.1k
Art, The Web, and Tiny UX
lynnandtonic
304
21k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
210
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
92
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
930
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