# This program forms and prints lists of words that are less, equal, and # greater than the average list length # To form the average correctly, there can be only one blank between each # pair of words import sys import string allLines = sys.stdin.readlines() allWords = [] for line in allLines: newline = line[0:-1] # remove newline words = string.split(newline) allWords = allWords + words sum = 0 for word in allWords: sum = sum + len(word) avg = float(sum) / len(allWords) # form a floating point average gtr = [] eql = [] lss = [] for word in allWords: if len(word) > avg: gtr = [word] + gtr elif len(word) == avg: eql = [word] + eql else: # len(word) < avg: lss = [word] + lss print "GTR" print gtr print "EQL" print eql print "LSS" print lss #foo #a b cc dd eee fff #gggg hhhh #iiiii jjjjj # python p5.py < foo #['jjjjj', 'iiiii', 'hhhh', 'gggg'] #['fff', 'eee'] #['dd', 'cc', 'b', 'a']