print(sumchanging sorter to read line by line this way may not be big performance boostthoughbecause the list sort method requires that the list already be complete as we'll see in manually coded sort algorithms are generally prone to be much slower than the python list sorting method interestinglythese two scripts can also be coded in much more compact fashion in python and later by using the new sorted built-in functiongenerator expressionsand file iterators the following work the same way as the originalswith noticeably less source-file real estatec:\pp \system\streamstype sortersmall py import sys for line in sorted(sys stdin)print(lineend='' :\pp \system\streamstype addersmall py import sys print(sum(int(linefor line in sys stdin)in its argument to sumthe latter of these employs generator expressionwhich is much like list comprehensionbut results are returned one at timenot in physical list the net effect is space optimization for more detailssee core language resourcesuch as the book learning python redirected streams and user interaction earlier in this sectionwe piped teststreams py output into the standard more commandline program with command like thisc:\pp \system\streamspython teststreams py input txt more but since we already wrote our own "morepaging utility in python in the preceding why not set it up to accept input from stdin toofor exampleif we change the last three lines of the more py file listed as example - in the prior if __name__ ='__main__'import sys if len(sys argv= more(sys stdin read()elsemore(open(sys argv[ ]read()when runnot when imported page stdin if no cmd args it almost seems as if we should be able to redirect the standard output of teststreams py into the standard input of more pyc:\pp \system\streamspython teststreams py input txt python \more py hello stream world enter number> squared is enter number> squared is enter number>bye standard streams