data
1 123
1 12
2 234
1 24
1 9
map.py
import sys
base_count = 10000
for line in sys.stdin:
key,value = line.strip().split("\t")
key = base_count + int(key)
print("%s\t%s"%(str(key),value))
reduce.py
import sys
current_key = None
result = []
base_count = 10000
for line in sys.stdin:
key,value = line.strip().split("\t")
key = int(key) - base_count
if current_key == None:
current_key = key
if current_key != key:
result.sort()
result = [str(i) for i in result]
print("%s\t%s"%(str(current_key),",".join(result)))
current_key = key
result = []
result.append(int(value))
result.sort()
result = [str(i) for i in result]
print("%s\t%s"%(str(current_key),",".join(result)))
result
1 9,12,24,123
2 234