tutorial introduction here' an example of hooking both of these generators together to create simple processing pipelinea python implementation of unix "tail - grep pythonwwwlog tail(open("access-log")pylines grep(wwwlog,"python"for line in pylinesprint linea subtle aspect of generators is that they are often mixed together with other iterable objects such as lists or files specificallywhen you write statement such as for item in ss could represent list of itemsthe lines of filethe result of generator functionor any number of other objects that support iteration the fact that you can just plug different objects in for can be powerful tool for creating extensible programs coroutines normallyfunctions operate on single set of input arguments howevera function can also be written to operate as task that processes sequence of inputs sent to it this type of function is known as coroutine and is created by using the yield statement as an expression (yieldas shown in this exampledef print_matches(matchtext)print "looking for"matchtext while trueline (yieldget line of text if matchtext in lineprint line to use this functionyou first call itadvance it to the first (yield)and then start sending data to it using send(for examplematcher print_matches("python"matcher next(advance to the first (yieldlooking for python matcher send("hello world"matcher send("python is cool"python is cool matcher send("yow!"matcher close(done with the matcher function call coroutine is suspended until value is sent to it using send(when this happensthat value is returned by the (yieldexpression inside the coroutine and is processed by the statements that follow processing continues until the next (yieldexpression is encountered--at which point the function suspends this continues until the coroutine function returns or close(is called on it as shown in the previous example coroutines are useful when writing concurrent programs based on producerconsumer problems where one part of program is producing data to be consumed by another part of the program in this modela coroutine represents consumer of data here is an example of using generators and coroutines togethera set of matcher coroutines matchers print_matches("python")print_matches("guido")print_matches("jython" lib fl ff