Answers for "python comprehension list with elif"

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 "python comprehension list with elif"

Python Answers by Framework

Browse Popular Code Answers by Language