if key in itemsprint(key"was found"elseprint(key"not found!"( was found not foundfor all keys let python check for match in generalit' good idea to let python do as much of the work as possible (as in this solutionfor the sake of brevity and performance the next example is similarbut builds list as it goes for later use instead of printing it performs typical data-structure task with for--collecting common items in two sequences (strings)--and serves as rough set intersection routine after the loop runsres refers to list that contains all the items found in seq and seq seq "spamseq "scamres [for in seq if in seq res append(xres [' '' '' 'start empty scan first sequence common itemadd to result end unfortunatelythis code is equipped to work only on two specific variablesseq and seq it would be nice if this loop could somehow be generalized into tool you could use more than once as you'll seethat simple idea leads us to functionsthe topic of the next part of the book this code also exhibits the classic list comprehension pattern--collecting results list with an iteration and optional filter test--and could be coded more concisely too[ for in seq if in seq [' '' '' 'let python collect results but you'll have to read on to the next for the rest of this story why you will carefile scanners in generalloops come in handy anywhere you need to repeat an operation or process something more than once because files contain multiple characters and linesthey are one of the more typical use cases for loops to load file' contents into string all at onceyou simply call the file object' read methodfile open('test txt'' 'print(file read()read contents into string but to load file in smaller piecesit' common to code either while loop with breaks on end-of-fileor for loop to read by characterseither of the following codings will suffice while and for loops