filter warnings_filter(infilefor in filteroutfile write(lokthat' pretty readablemaybe at least it' short but what on earth is going on hereit makes no sense whatsoever and what is yieldanywayin factyield is the key to generators when python sees yield in functionit takes that function and wraps it up in an object not unlike the one in our previous example think of the yield statement as similar to the return statementit exits the function and returns line unlike returnhoweverwhen the function is called again (via next())it will start where it left off--on the line after the yield statement--instead of at the beginning of the function in this examplethere is no line "afterthe yield statementso it jumps to the next iteration of the for loop since the yield statement is inside an if statementit only yields lines that contain warning while it looks like this is just function looping over the linesit is actually creating special type of objecta generator objectprint(warnings_filter([]) passed an empty list into the function to act as an iterator all the function does is create and return generator object that object has __iter__ and __ next__ methods on itjust like the one we created in the previous example whenever __next__ is calledthe generator runs the function until it finds yield statement it then returns the value from yieldand the next time __next__ is calledit picks up where it left off this use of generators isn' that advancedbut if you don' realize the function is creating an objectit can seem like magic this example was quite simplebut you can get really powerful effects by making multiple calls to yield in single functionthe generator will simply pick up at the most recent yield and continue to the next one yield items from another iterable oftenwhen we build generator functionwe end up in situation where we want to yield data from another iterable objectpossibly list comprehension or generator expression we constructed inside the generatoror perhaps some external items that were passed into the function this has always been possible by looping over the iterable and individually yielding each item howeverin python version the python developers introduced new syntax to make this little more elegant