Parallel Python
import glob
import sys

from functools import reduce

def count_lines_in_file(filename):
    Function that returns the number of lines
    of text in the file 'filename'
    with open(filename) as f:
        return len(f.readlines())

# get all of the names of the plays from the command line
filenames = sorted(glob.glob(f"{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))

# Now print out all of the totals
string_results = map(lambda x, y: "%s contains %s lines" % (x, y), filenames, play_line_count)

# Join the list of strings using a newline character
# and print to screen.

total = reduce(lambda x,y: x+y, play_line_count)

print("The total number of lines is %s." % total)
python shakespeare
shakespeare/README contains 2 lines
shakespeare/allswellthatendswell contains 4515 lines
shakespeare/antonyandcleopatra contains 5998 lines
shakespeare/asyoulikeit contains 4122 lines
shakespeare/comedyoferrors contains 2937 lines
shakespeare/coriolanus contains 5836 lines
shakespeare/cymbeline contains 5485 lines
shakespeare/hamlet contains 6045 lines
shakespeare/juliuscaesar contains 4107 lines
shakespeare/kinglear contains 5525 lines
shakespeare/loveslabourslost contains 4335 lines
shakespeare/macbeth contains 3876 lines
shakespeare/measureforemeasure contains 4337 lines
shakespeare/merchantofvenice contains 3883 lines
shakespeare/merrywivesofwindsor contains 4448 lines
shakespeare/midsummersnightsdream contains 3115 lines
shakespeare/muchadoaboutnothing contains 4063 lines
shakespeare/othello contains 5424 lines
shakespeare/periclesprinceoftyre contains 3871 lines
shakespeare/romeoandjuliet contains 4766 lines
shakespeare/tamingoftheshrew contains 4148 lines
shakespeare/tempest contains 3399 lines
shakespeare/timonofathens contains 3973 lines
shakespeare/titusandronicus contains 3767 lines
shakespeare/troilusandcressida contains 5443 lines
shakespeare/twelfthnight contains 4017 lines
shakespeare/twogentlemenofverona contains 3605 lines
shakespeare/winterstale contains 4643 lines
The total number of lines is 119685.