Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

ternary operator in list comprehension python

# Format: list = ['value if true' if condition else 'value if false' for item in iterable]
# Example
list_name = [True if num<5 else False for num in range(10)]
 
PREVIOUS NEXT
Tagged: #ternary #operator #list #comprehension #python
ADD COMMENT
Topic
Name
3+4 =