Answers for "can you elif with list comprehension python"

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

Python Answers by Framework

Browse Popular Code Answers by Language