第一关 成绩统计
- 任务描述
使用Map/Reduce
计算班级中年龄最大的学生。
- 代码实现
1.mapper函数:
# 使用name,age分别表示姓名和年龄
def mapper(line):
########## begin ############
group = line.split('\\n')
for people in group:
if len(people.strip()) == 0:
continue
name, age = people.split(' ')
########### End #################
print("%s\t%s" % (name, age))
mapper函数输入的是一行一行的数据,对每一行数据用‘\n’进行分割得到的是<姓名 年龄>这样的字符串,再次分割得到name = 姓名,age = 年龄 ,输出。
2.reducer函数
# 找出values的最大值,并按name\tmax_age的形式输出。
def reducer(k, values):
##### Begin #########
print("%s\t%s" % (k,max(values)))
##### En