Answers for "elif condition in list comprehension"

1

python list comprehension elif

>>> l = [1, 2, 3, 4, 5]
>>> ['yes' if v == 1 else 'no' if v == 2 else 'idle' for v in l]
['yes', 'no', 'idle', 'idle', 'idle']
Posted by: Guest on November-16-2020

Code answers related to "elif condition in list comprehension"

Python Answers by Framework

Browse Popular Code Answers by Language