alpha尝鲜安装和Hello world(2)

#!/usr/bin/python
#-*- encoding:UTF-8 -*-
#reduce.py
import sys

import string

res = {}
#声明字典

for line in sys.stdin:
                try:
                                flags = line[:-1].split('\t')
                                if len(flags) != 2:
                                                continue
                                field_key = flags[0]
                                if res.has_key(field_key) == False:
                                                res[field_key] = 0
                                res[field_key] += 1
                except Exception,e:
                                pass

for key in res.keys():
                print key+','+'%s' % (res[key])

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/4b4dbc4c4a331366130f2cd1d4a145e7.html