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
58
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
63
The Command Line Interface
eloy
2
480
Python Decorators
eloy
8
630
Other Decks in Programming
See All in Programming
LINEヤフー データグループ紹介
lycorp_recruit_jp
0
700
データベースコネクションプール(DBCP)の変遷と理解
fujikawa8
1
260
Claude Codeの使い方
ttnyt8701
1
120
Cloudflare Realtime と Workers でつくるサーバーレス WebRTC
nekoya3
0
410
GraphRAGの仕組みまるわかり
tosuri13
7
390
Webからモバイルへ Vue.js × Capacitor 活用事例
naokihaba
0
700
The Evolution of Enterprise Java with Jakarta EE 11 and Beyond
ivargrimstad
1
750
Javaのルールをねじ曲げろ!禁断の操作とその代償から学ぶメタプログラミング入門 / A Guide to Metaprogramming: Lessons from Forbidden Techniques and Their Price
nrslib
3
2k
AWS CDKの推しポイント 〜CloudFormationと比較してみた〜
akihisaikeda
3
280
業務自動化をJavaとSeleniumとAWS Lambdaで実現した方法
greenflagproject
1
120
AIエージェントによるテストフレームワーク Arbigent
takahirom
0
380
単体テストの始め方/作り方
toms74209200
0
470
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
269
20k
Optimizing for Happiness
mojombo
379
70k
Code Reviewing Like a Champion
maltzj
524
40k
Automating Front-end Workflow
addyosmani
1370
200k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
32
5.9k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
Docker and Python
trallard
44
3.4k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
137
34k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.6k
How to train your dragon (web standard)
notwaldorf
92
6.1k
Six Lessons from altMBA
skipperchong
28
3.8k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.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