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
58
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
67
The Command Line Interface
eloy
2
490
Python Decorators
eloy
8
630
Other Decks in Programming
See All in Programming
bootcamp2025_バックエンド研修_WebAPIサーバ作成.pdf
geniee_inc
0
130
CSC509 Lecture 07
javiergs
PRO
0
240
モテるデスク環境
mozumasu
3
1.3k
Claude CodeによるAI駆動開発の実践 〜そこから見えてきたこれからのプログラミング〜
iriikeita
0
330
Go言語の特性を活かした公式MCP SDKの設計
hond0413
2
510
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
460
チームの境界をブチ抜いていけ
tokai235
0
220
ALL CODE BASE ARE BELONG TO STUDY
uzulla
28
6.7k
AI 駆動開発におけるコミュニティと AWS CDK の価値
konokenj
5
240
TransformerからMCPまで(現代AIを理解するための羅針盤)
mickey_kubo
7
5.2k
Catch Up: Go Style Guide Update
andpad
0
250
O Que É e Como Funciona o PHP-FPM?
marcelgsantos
0
200
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
97
6.3k
Designing for humans not robots
tammielis
254
26k
Speed Design
sergeychernyshev
32
1.2k
Art, The Web, and Tiny UX
lynnandtonic
303
21k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.5k
Java REST API Framework Comparison - PWX 2021
mraible
34
8.9k
A designer walks into a library…
pauljervisheath
209
24k
A better future with KSS
kneath
239
18k
Thoughts on Productivity
jonyablonski
70
4.9k
We Have a Design System, Now What?
morganepeng
53
7.8k
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
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