Week 10: Conditionals and List Comprehension
ternary operation
A conditional expression that has three operands
conditional list comprehensions
A list comprehension can be extended with an optional conditional caluse that causes the statement to return a list with only certain elements
Coditional expression
Works to assign a variable to with an if else in one line, only works if trying to assign same variable within if-else branch.
Conditional expression format
has the form exprWhenTrue if condition else exprWhenFalse
List comprehension
iterates over a list, modifies each element, and returns a new list consisting of the modified elements
List comprehension format
new_list = [expression for loop_variable_name in iterable]
Conditional list comprehensions format
new_list = [expression for name in iterable if condtion]