is pif notthe line is omitted from the result list this is fairly big expressionbut it' easy to understand if we translate it to its simple for loop statement equivalent in generalwe can always translate list comprehension to for statement by appending as we go and further indenting each successive partres [for line in open('script py')if line[ =' 'res append(line rstrip()res ['print(sys path)''print( * )'this for statement equivalent worksbut it takes up four lines instead of one and may run slower in factyou can squeeze substantial amount of logic into list comprehension when you need to--the following works like the prior but selects only lines that end in digit (before the newline at the end)by filtering with more sophisticated expression on the right side[line rstrip(for line in open('script py'if line rstrip()[- isdigit()[' 'as another if filter examplethe first result in the following gives the total lines in text fileand the second strips whitespace on both ends to omit blank links in the tally in just one line of code (this filenot includedcontains lines describing typos found in the first draft of this book by my proofreader)fname ' :\books\ \lp \draft typos txtlen(open(fnamereadlines() len([line for line in open(fnameif line strip(!''] all lines nonblank lines nested loopsfor list comprehensions can become even more complex if we need them to--for instancethey may contain nested loopscoded as series of for clauses in facttheir full syntax allows for any number of for clauseseach of which can have an optional associated if clause for examplethe following builds list of the concatenation of for every in one string and every in another it effectively collects all the ordered combinations of the characters in two strings[ for in 'abcfor in 'lmn'['al''am''an''bl''bm''bn''cl''cm''cn'againone way to understand this expression is to convert it to statement form by indenting its parts the following is an equivalentbut likely sloweralternative way to achieve the same effect iterations and comprehensions