##language:zh #pragma section-numbers off ##含有章节索引导航的 ZPyUG 文章通用模板 <> ## 默许导航,请保留 <> = CPyUG Top 100 = {{{ 23号 sender-time Sent at 13:26 (GMT+08:00). Current time there: 8:31 PM. ✆ reply-to python-cn@googlegroups.com to python-cn@googlegroups.com date Fri, Mar 19, 2010 at 13:26 subject [CPyUG] [OT] 比较无聊,写一个CPyUG Top 100 }}} ##startInc == 代码 == {{{ #!python #!/usr/bin/env python # -*- coding: UTF-8 -*- import re, sys, os from operator import itemgetter from collections import defaultdict pat = re.compile('From:\s+?.*<([\da-z_\.-]+@[\da-z\.-]+)>') mails = defaultdict(int) for line in open(sys.argv[1], 'rb'): if line[0] != 'F': continue mat = pat.match(line) if mat: mails[mat.group(1)] += 1 lst = sorted(mails.iteritems(), key=itemgetter(1), reverse=True) for t in lst[:100 if 100 < len(lst) else len(lst)]: print '%s : %d' % (t[0].ljust(16), t[1]) }}} === 试跑 === {{{ Shell:~ >: python CPyUG_Top100.py Mail/CPyUG jhuangjiahua@gmail.com : 966 limodou@gmail.com : 960 askfor@gmail.com : 908 zoom.quiet@gmail.com : 834 zhicheng1988@gmail.com : 625 linjunhalida@gmail.com : 544 march.liu@gmail.com : 524 smallfish.xy@gmail.com : 455 ... python CPyUG_Top100.py Mail/CPyUG 4.10s user 0.22s system 99% cpu 4.332 total Shell:~ >: }}} ##endInc ---- '''反馈''' 创建 by -- ZoomQuiet [<>]