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
42
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
50
The Command Line Interface
eloy
2
470
Python Decorators
eloy
8
620
Other Decks in Programming
See All in Programming
Build Apps for iOS, Android & Desktop in 100% Kotlin With Compose Multiplatform (mDevCamp 2024)
zsmb
0
470
PostmanでAPIの動作確認が楽になった話
h455h1
0
180
CA.swift19 恋するAIアプリ開発の裏側
oskmr
0
380
Behind VS Code Extensions for JavaScript / TypeScript Linnting and Formatting
unvalley
6
1.3k
Ruby Pattern Matching
bkuhlmann
0
930
冗長なエラーログを削減し、スタックトレースを手に入れる / Reducing Verbose Error Logs and Obtaining Stack Traces
upamune
0
1.1k
Elm 0.19.0 Changes
bkuhlmann
0
510
Sheets API使ってみた
toshi0383
2
170
DMMプラットフォームがTiDB Cloudを採用した背景
pospome
9
4.3k
スキーマ駆動開発による品質とスピードの両立 - 私達は何故、スキーマを書くのか
kentaroutakeda
0
180
Compose-View Interop in Practice (mDevCamp 2024)
stewemetal
0
170
検証も兼ねて個人開発でHonoとかと向き合った話
hanetsuki
1
1.3k
Featured
See All Featured
Side Projects
sachag
451
41k
Designing the Hi-DPI Web
ddemaree
276
33k
How GitHub Uses GitHub to Build GitHub
holman
468
290k
Why Our Code Smells
bkeepers
PRO
331
56k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
245
20k
The MySQL Ecosystem @ GitHub 2015
samlambert
244
12k
Into the Great Unknown - MozCon
thekraken
15
1k
Debugging Ruby Performance
tmm1
70
11k
Keith and Marios Guide to Fast Websites
keithpitt
408
22k
Building Flexible Design Systems
yeseniaperezcruz
320
37k
Facilitating Awesome Meetings
lara
43
5.6k
Designing on Purpose - Digital PM Summit 2013
jponch
111
6.5k
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