I need some help creating a Map Reduce function in Python from an edge list.
Given the following list:
A,B
A,C
A,D
B,C
C,A
C,B
D,A
My code should follow the format below. My goal is to display a degree list along with the count of degrees.
map(key, value):
//key: document name; value: text of the document
for each word w in value:
emit(w, 1)
reduce(key, values):
//key: a word; value: an iterator over counts
result = 0
for each count v in values:
result += v
emit(key, result)
Loops have always been a struggle for me. Can someone point me in the right direction?
The output should be as follows:
Degree Count
1 2
2 1
3 1
The code should work for any data set similarly formatted
So, as I understand it, I need to count the number of different values each letter is paired with--this would be the "degree" (A, for example, is degree 3), and then total the pairs according to the degree--this would be the "count".
Could the key be the pair of values?
map(key, value):
//key: document name; value: text of the document
for each word w in value:
emit([x,y], 1)