Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
73
The Command Line Interface
eloy
2
490
Python Decorators
eloy
8
630
Other Decks in Programming
See All in Programming
WebRTC と Rust と8K 60fps
tnoho
2
1.9k
まだ間に合う!Claude Code元年をふりかえる
nogu66
3
470
AIコーディングエージェント(skywork)
kondai24
0
150
【CA.ai #3】Google ADKを活用したAI Agent開発と運用知見
harappa80
0
290
Navigation 3: 적응형 UI를 위한 앱 탐색
fornewid
1
220
TUIライブラリつくってみた / i-just-make-TUI-library
kazto
1
360
Building AI Agents with TypeScript #TSKaigiHokuriku
izumin5210
6
1.3k
AWS CDKの推しポイントN選
akihisaikeda
1
240
なあ兄弟、 余白の意味を考えてから UI実装してくれ!
ktcryomm
11
11k
全員アーキテクトで挑む、 巨大で高密度なドメインの紐解き方
agatan
8
20k
認証・認可の基本を学ぼう後編
kouyuume
0
180
モデル駆動設計をやってみようワークショップ開催報告(Modeling Forum2025) / model driven design workshop report
haru860
0
260
Featured
See All Featured
[SF Ruby Conf 2025] Rails X
palkan
0
490
Six Lessons from altMBA
skipperchong
29
4.1k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
4 Signs Your Business is Dying
shpigford
186
22k
Code Reviewing Like a Champion
maltzj
527
40k
Typedesign – Prime Four
hannesfritz
42
2.9k
Side Projects
sachag
455
43k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
700
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.4k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
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