Week 10: Conditionals and List Comprehension

Ace your homework & exams now with Quizwiz!

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]


Related study sets

Entrepreneurship Study Guide: Test 5

View Set

Responding to Violence and Abuse Practice

View Set

Public Opinion and the Media in TexasAssignment

View Set

Multiple Choice Homework for Quiz4

View Set

Chapter 17 Investing in Real Estate and Other Investment Alternatives

View Set