Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

list comprehension if-else

In general,
[f(x) if condition else g(x) for x in sequence]

And, for list comprehensions with if conditions only,
[f(x) for x in sequence if condition]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #list #comprehension
ADD COMMENT
Topic
Name
1+5 =