Reduction : Answer to exercise 1
from functools import reduce
Function that returns the number of lines
of text in the file 'filename'
with open(filename) as f:
# get all of the names of the plays from the command line
filenames = sys.argv[1:]
# map the count_lines function against all of the
# files listed in "filenames"
play_line_count = list(map(count_lines_in_file, filenames))
# print out the filenames of the plays along with their line counts
def add(x, y):
"""Return the sum of the two arguments"""
return x + y
total = reduce(add, play_line_count)
print("The total number of lines is %s." % total)