in the prior filter and reduce are in ' functional programming domainso we'll defer their details for nowthe point to notice here is their use of the iteration protocol for files and other iterables we first saw the sorted function used here at work inand we used it for dictionaries in sorted is built-in that employs the iteration protocol--it' like the original list sort methodbut it returns the new sorted list as result and runs on any iterable object notice thatunlike map and otherssorted returns an actual list in python instead of an iterable interestinglythe iteration protocol is even more pervasive in python today than the examples so far have demonstrated--essentially everything in python' built-in toolset that scans an object from left to right is defined to use the iteration protocol on the subject object this even includes tools such as the list and tuple built-in functions (which build new objects from iterables)and the string join method (which makes new string by putting substring between strings contained in an iterableconsequentlythese will also work on an open file and automatically read one line at timelist(open('script py')['import sys\ ''print(sys path)\ '' \ ''print( * )\ 'tuple(open('script py')('import sys\ ''print(sys path)\ '' \ ''print( * )\ ''&&join(open('script py')'import sys\ &&print(sys path)\ && \ &&print( * )\neven some tools you might not expect fall into this category for examplesequence assignmentthe in membership testslice assignmentand the list' extend method also leverage the iteration protocol to scanand thus read file by lines automaticallyabcd open('script py'ad ('import sys\ ''print( * )\ 'sequence assignment * open('script py' extended form ab ('import sys\ '['print(sys path)\ '' \ ''print( * )\ ']' \nin open('script py'false ' \nin open('script py'true membership test [ slice assignment [ : open('script py' [ 'import sys\ ''print(sys path)\ '' \ ''print( * )\ ' [ extend(open('script py')list extend method other iteration contexts