combs [for in [ , , ]for in [ , , ]if !ycombs append((xy)combs [( )( )( )( )( )( )( )note how the order of the for and if statements is the same in both these snippets if the expression is tuple ( the (xyin the previous example)it must be parenthesized vec [- - create new list with the values doubled [ * for in vec[- - filter the list to exclude negative numbers [ for in vec if > [ apply function to all the elements [abs(xfor in vec[ call method on each element freshfruit [banana'loganberry ''passion fruit '[weapon strip(for weapon in freshfruit['banana''loganberry''passion fruit'create list of -tuples like (numbersquare[(xx** for in range( )[( )( )( )( )( )( )the tuple must be parenthesizedotherwise an error is raised [xx** for in range( )file ""line in [xx** for in range( )syntaxerrorinvalid syntax flatten list using listcomp with two 'forvec [[ , , ][ , , ][ , , ][num for elem in vec for num in elem[ list comprehensions can contain complex expressions and nested functionsfrom math import pi [str(round(pii)for in range( )[' '' '' '' '' 'nested list comprehensions the initial expression in list comprehension can be any arbitrary expressionincluding another list comprehension consider the following example of matrix implemented as list of lists of length matrix [ ][ ](continues on next page data structures