Between map and reduce sits the shuffle: the framework's job of bringing every value for the same key together. All the ("b", 1) pairs from different mappers, possibly on different machines, are grouped so the reducer sees one key and the full list of its values. This regrouping is the quiet heavy lifting that makes the model work.
Build the shuffle:
shuffle(pairs): return a dict mapping each key to the list of its values, in the order the pairs arrived.def shuffle(pairs):
"""Group values by key: [(k, v)...] -> {k: [v...]}."""
groups = {}
# TODO: visit the pairs in order and file each value under its key in the
# groups dict, starting a fresh list the first time a key appears and adding
# to the existing one after that, so arrival order survives within a key.
# Return groups; a key shows up once no matter how many pairs carried it.
pass
The editor and the test runner need a wide screen. Open this page on a desktop browser and your progress will be waiting.
Between map and reduce sits the shuffle: the framework's job of bringing every value for the same key together. All the ("b", 1) pairs from different mappers, possibly on different machines, are grouped so the reducer sees one key and the full list of its values. This regrouping is the quiet heavy lifting that makes the model work.
Build the shuffle:
shuffle(pairs): return a dict mapping each key to the list of its values, in the order the pairs arrived.Press Run Tests or ββ© to check your solution.