【发布时间】:2018-04-09 03:07:58
【问题描述】:
[01/Aug/1995:00:54:59 -0400] "GET /images/opf-logo.gif HTTP/1.0" 200 32511 [01/Aug/1995:00:55:04 -0400] “获取 /images/ksclogosmall.gif HTTP/1.0" 200 4635 [01/Aug/1995:00:55:06 -0400] "GET /images/ksclogosmall.gif HTTP/1.0" 403 78787
我有一个来自 HTTP 服务器的文件,我需要根据最后一列的大小(以字节为单位)的累积总和列出前 10 个图像。
li = [i.strip().split() for i in open("input.txt").readlines()]
sorted_li = sorted(li, key = lambda cols : int(cols[6]), reverse = True)
sorted_out = {}
for l in sorted_li:
if l[3] in sorted_out:
sorted_out[l[3]] += int(l[6])
else:
sorted_out[l[3]] = int(l[6])
如何限制字典中的前 10 个值?有没有办法不使用 pandas 和 group by?
【问题讨论】:
标签: python cumulative-sum