functions and functional programming in this casewe use the coroutine in the same way as before howevernow calls to send(also produce result for examples line_splitter("," next(ready to split send(" , , "[' '' ''cs send(" , , "[' '' '' 'understanding the sequencing of this example is critical the first next(call advances the coroutine to (yield result)which returns nonethe initial value of result on subsequent send(callsthe received value is placed in line and split into result the value returned by send(is the value passed to the next yield statement encountered in other wordsthe value returned by send(comes from the next yield expressionnot the one responsible for receiving the value passed by send(if coroutine returns valuessome care is required if exceptions raised with throw(are being handled if you raise an exception in coroutine using throw()the value passed to the next yield in the coroutine will be returned as the result of throw(if you need this value and forget to save itit will be lost using generators and coroutines at first glanceit might not be obvious how to use generators and coroutines for practical problems howevergenerators and coroutines can be particularly effective when applied to certain kinds of programming problems in systemsnetworkingand distributed computation for examplegenerator functions are useful if you want to set up processing pipelinesimilar in nature to using pipe in the unix shell one example of this appeared in the introduction here is another example involving set of generator functions related to findingopeningreadingand processing filesimport os import fnmatch def find_files(topdirpattern)for pathdirnamefilelist in os walk(topdir)for name in filelistif fnmatch fnmatch(namepattern)yield os path join(path,nameimport gzipbz def opener(filenames)for name in filenamesif name endswith(gz") gzip open(nameelif name endswith(bz ") bz bz file(nameelsef open(nameyield def cat(filelist)for in filelistfor line in fyield line def grep(patternlines)for line in linesif pattern in lineyield line lib fl ff