Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

list comprehension if elseif

>>> 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']
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #list #comprehension #elseif
ADD COMMENT
Topic
Name
9+2 =