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
63
0
Share
The `max` function
Using the `max` function in python 3.6. Some caveats to watch out for.
Eloy Zuniga Jr.
April 17, 2018
More Decks by Eloy Zuniga Jr.
See All by Eloy Zuniga Jr.
The Filter Function
eloy
0
79
The Command Line Interface
eloy
2
490
Python Decorators
eloy
8
640
Other Decks in Programming
See All in Programming
The Less-Told Story of Socket Timeouts
coe401_
3
580
Kingdom of the Machine
yui_knk
2
750
GoogleCloudとterraform完全に理解した
terisuke
1
130
iOS機能開発のAI環境と起きた変化
ryunakayama
0
190
Surviving Black Friday: 329 billion requests with Falcon!
ioquatix
0
730
Spec Driven Development | AI Summit Vilnius
danielsogl
PRO
1
110
The Monolith Strikes Back: Why AI Agents ❤️ Rails Monoliths
serradura
0
340
「話せることがない」を乗り越える 〜日常業務から登壇テーマをつくる思考法〜
shoheimitani
4
840
Oxlintとeslint-plugin-react-hooks 明日から始められそう?
t6adev
0
280
NakouPAY説明用
annouim0
0
250
Server-Side Kotlin LT大会 vol.18 [Kotlin-lspの最新情報と Neovimのlsp設定例]
yasunori0418
1
170
Coding at the Speed of Thought: The New Era of Symfony Docker
dunglas
0
5k
Featured
See All Featured
Fireside Chat
paigeccino
42
3.9k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
Darren the Foodie - Storyboard
khoart
PRO
3
3.3k
The Pragmatic Product Professional
lauravandoore
37
7.2k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Designing for Performance
lara
611
70k
Test your architecture with Archunit
thirion
1
2.2k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
190
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
240
KATA
mclloyd
PRO
35
15k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
270
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