python 统计文件top IP

lines = '''
1.2.2.3
1.21.29.19
....
''' cnt = {} for line in lines.split(): if line not in cnt: cnt[line] = 0 cnt[line] += 1 print cnt out = cnt.items() out.sort(lambda a,b:-cmp(a[1],b[1])) print out

 

posted @ 2017-09-22 11:20  bonelee  阅读(398)  评论(0编辑  收藏  举报