['import sys\ ''print(sys path)\ '' \ ''print( * )\ '[line rstrip(upper(for line in open('script py')['import sys''print(sys path)'' ''print( * )'[line split(for line in open('script py')[['import''sys']['print(sys path)'][' ''='' ']['print( ''**'' )'][line replace(''!'for line in open('script py')['import!sys\ ''print(sys path)\ '' !=! \ ''print( !**! )\ '[('sysin lineline[: ]for line in open('script py')[(true'impor')(true'print')(false' ')(false'print')recall that the method chaining in the second of these examples works because string methods return new stringto which we can apply another string method the last of these shows how we can also collect multiple resultsas long as they're wrapped in collection like tuple or list one fine point hererecall from that file objects close themselves automatically when garbage-collected if still open hencethese list comprehensions will also automatically close the file when their temporary file object is garbage-collected after the expression runs outside cpythonthoughyou may want to code these to close manually if this is run in loopto ensure that file resources are freed immediately see for more on file close calls if you need refresher on this extended list comprehension syntax in factlist comprehensions can be even richer in practiceand even constitute sort of iteration mini-language in their fullest forms let' take quick look at their syntax tools here filter clausesif as one particularly useful extensionthe for loop nested in comprehension expression can have an associated if clause to filter out of the result items for which the test is not true for examplesuppose we want to repeat the prior section' file-scanning examplebut we need to collect only lines that begin with the letter (perhaps the first character on each line is an action code of some sortadding an if filter clause to our expression does the tricklines [line rstrip(for line in open('script py'if line[ =' 'lines ['print(sys path)''print( * )'list comprehensionsa first detailed look