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
66
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
83
The Command Line Interface
eloy
2
500
Python Decorators
eloy
8
640
Other Decks in Programming
See All in Programming
cloudnative conference 2026 flyle
azihsoyn
1
210
プロパティの順序で型推論が壊れる!? TypeScript6.0の修正からContext-Sensitivityの仕組みを追う
bicstone
2
1k
20260514 - build with ai 2026 - build LINE Bot with Gemini CLI
line_developers_tw
PRO
0
470
次世代リンターで探る、tsgo 時代における型認識カスタムルールの現実解
ytakahashii
1
970
CSC307 Lecture 17
javiergs
PRO
0
240
実践ハーネスエンジニアリング:ステアリングループを実例から読み解く / Practical Harness Engineering: Understanding Steering Loops Through Real-World Examples
nrslib
6
6.2k
関係性から理解する"同一性"の型用語たち
pvcresin
2
520
TypeSpec で繋ぐ複数プロダクトの型安全
maroon8021
1
240
Spec-Driven Development with AI-Agents: From High-Level Requirements to Working Software
antonarhipov
2
330
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.6k
AI時代だからこそ「Bloc」を採用する価値があるのかもしれない
takuroabe
0
230
色即是空、空即是色、データサイエンス
kamoneggi
1
160
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Everyday Curiosity
cassininazir
0
210
KATA
mclloyd
PRO
35
15k
Building an army of robots
kneath
306
46k
Claude Code のすすめ
schroneko
67
220k
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.5k
The Curse of the Amulet
leimatthew05
1
12k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2k
Become a Pro
speakerdeck
PRO
31
5.9k
The World Runs on Bad Software
bkeepers
PRO
72
12k
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