The readings for Wednesday, March 1 are:
The focus of this reading is to introduce you to functional programming in Python and MapReduce.
Optional Resources
Given the following Python script, evens.py
:
#!/usr/bin/env python2.7 import sys results = [] for number in sys.stdin: number = number.strip() if int(number) % 2 == 0: results.append(number) print ' '.join(results)
A. Create a second version of this script called evens_fp.py
that
re-implements the evens.py
script in one line using map,
filter, and lambda.
B. Create a third version of this script called evens_lc.py
that
re-implements the evens.py
script in one line using list
comprehensions.
Note, both scripts should look like this:
#!/usr/bin/env python2.7 import sys print ' '.join(...)
Where the ...
is where your one line should go.
C. Create a fourth version of this script called evens_gr.py
that
re-implements the evens.py
script by creating a generator function
using the yield keyword.
This script should look like this:
#!/usr/bin/env python2.7 import sys def evens(stream): ... print ' '.join(evens(sys.stdin))
Where the ...
is where your generator code should go.
To test your scripts, you should be able to reproduce the following output:
$ seq 1 10 | ./evens_fp.py 2 4 6 8 10 $ seq 1 10 | ./evens_lc.py 2 4 6 8 10 $ seq 1 10 | ./evens_gr.py 2 4 6 8 10
In your reading06/README.md
file, answer the following questions:
A. What problem is MapReduce trying to solve?
B. Describe the three phases of a typical MapReduce workflow.
If you have any questions, comments, or concerns regarding the course, please provide your feedback at the end of your response.
To submit your assignment, please commit your work to the reading06
folder
in your assignments GitLab repository. Your reading06
folder should
only contain the following files:
README.md
evens_fp.py
evens_lc.py
evens_gr.py