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
52
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
58
The Command Line Interface
eloy
2
470
Python Decorators
eloy
8
620
Other Decks in Programming
See All in Programming
XStateを用いた堅牢なReact Components設計~複雑なClient Stateをシンプルに~ @React Tokyo ミートアップ #2
kfurusho
1
910
チームリードになって変わったこと
isaka1022
0
200
Honoのおもしろいミドルウェアをみてみよう
yusukebe
1
210
Software Architecture
hschwentner
6
2.1k
『GO』アプリ データ基盤のログ収集システムコスト削減
mot_techtalk
0
120
『品質』という言葉が嫌いな理由
korimu
0
160
Honoとフロントエンドの 型安全性について
yodaka
7
1.2k
Honoをフロントエンドで使う 3つのやり方
yusukebe
7
3.3k
Immutable ActiveRecord
megane42
0
140
dbt Pythonモデルで実現するSnowflake活用術
trsnium
0
160
社内フレームワークとその依存性解決 / in-house framework and its dependency management
vvakame
1
560
ペアーズでの、Langfuseを中心とした評価ドリブンなリリースサイクルのご紹介
fukubaka0825
2
320
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.3k
A better future with KSS
kneath
238
17k
StorybookのUI Testing Handbookを読んだ
zakiyama
28
5.5k
Automating Front-end Workflow
addyosmani
1368
200k
The World Runs on Bad Software
bkeepers
PRO
67
11k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Building a Scalable Design System with Sketch
lauravandoore
461
33k
How to Ace a Technical Interview
jacobian
276
23k
Unsuck your backbone
ammeep
669
57k
For a Future-Friendly Web
brad_frost
176
9.5k
Being A Developer After 40
akosma
89
590k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
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