Using "else" in a comprehension in Python

Published: 20 July 2024
on channel: Python Morsels
347
31

While list comprehesions in Python don't support the else keyword directly, conditional expressions can be embedded within list comprehension.

Article at https://pym.dev/comprehension-with-else/

More #Python screencasts at https://pym.dev/screencasts/

00:00 Do list comprehensions support else?
00:25 But else does work in comprehensions...
00:46 Python's ternary operator
01:09 Conditional expressions in list comprehension
01:26 Making more readable list comprehensions
02:06 Avoid complex comprehensions
02:28 Python's list comprehensions and if-else


Watch video Using "else" in a comprehension in Python online without registration, duration hours minute second in high quality. This video was added by user Python Morsels 20 July 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 347 once and liked it 31 people.