[ all of these use the modulus (remainder of divisionoperator%to detect even numbersif there is no remainder after dividing number by it must be even the filter call here is not much longer than the list comprehension either howeverwe can combine an if clause and an arbitrary expression in our list comprehensionto give it the effect of filter and mapin single expression[ * for in range( if = [ this timewe collect the squares of the even numbers from through the for loop skips numbers for which the attached if clause on the right is falseand the expression on the left computes the squares the equivalent map call would require lot more work on our part--we would have to combine filter selections with map iterationmaking for noticeably more complex expressionlistmap((lambda xx** )filter((lambda xx = )range( ))[ formal comprehension syntax in factlist comprehensions are more general still in their simplest formyou must always code an accumulation expression and single for clauseexpression for target in iterable though all other parts are optionalthey allow richer iterations to be expressed--you can code any number of nested for loops in list comprehensionand each may have an optional associated if test to act as filter the general structure of list comprehensions looks like thisexpression for target in iterable if condition for target in iterable if condition for targetn in iterablen if conditionn this same syntax is inherited by set and dictionary comprehensions as well as the generator expressions coming upthough these use different enclosing characters (curly braces or often-optional parentheses)and the dictionary comprehension begins with two expressions separated by colon (for key and valuewe experimented with the if filter clause in the previous section when for clauses are nested within list comprehensionthey work like equivalent nested for loop statements for exampleres [ for in [ for in [ ]res [ this has the same effect as this substantially more verbose equivalentres [for in [ ] comprehensions and generations