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
54
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
59
The Command Line Interface
eloy
2
470
Python Decorators
eloy
8
620
Other Decks in Programming
See All in Programming
The Clean ArchitectureがWebフロントエンドでしっくりこないのは何故か / Why The Clean Architecture does not fit with Web Frontend
twada
PRO
56
18k
Lambdaの監視、できてますか?Datadogを用いてLambdaを見守ろう
nealle
2
790
楽しく向き合う例外対応
okutsu
0
740
DRFを少しずつ オニオンアーキテクチャに寄せていく DjangoCongress JP 2025
nealle
2
300
複数のAWSアカウントから横断で 利用する Lambda Authorizer の作り方
tc3jp
0
130
Webフレームワークとともに利用するWeb components / JSConf.jp おかわり
spring_raining
1
140
Go 1.24でジェネリックになった型エイリアスの紹介
syumai
2
310
kintone開発を効率化するためにチームで試した施策とその結果を大放出!
oguemon
0
350
Datadog DBMでなにができる? JDDUG Meetup#7
nealle
0
160
はじめての Go * WASM * OCR
sgash708
1
120
Drawing Heighway’s Dragon- Recursive Function Rewrite- From Imperative Style in Pascal 64 To Functional Style in Scala 3
philipschwarz
PRO
0
160
AWS Step Functions は CDK で書こう!
konokenj
5
910
Featured
See All Featured
Embracing the Ebb and Flow
colly
84
4.6k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
4
390
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.7k
How STYLIGHT went responsive
nonsquared
99
5.4k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
12k
The Cult of Friendly URLs
andyhume
78
6.2k
The World Runs on Bad Software
bkeepers
PRO
67
11k
Making Projects Easy
brettharned
116
6k
YesSQL, Process and Tooling at Scale
rocio
172
14k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
Automating Front-end Workflow
addyosmani
1369
200k
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