在日志文件中记录着每次访问的query,现在需要找到最热门的10个query
我们首先定义数据结构
class Query(object):
def __init__(self,term,count):
self.term=term
self.count=count
def __cmp__(self,obj):
return cmp(self.count,obj.count)
def __str__(self):
return ‘%s:%d‘ %(self.term,self.count)
__repr__ = __str__
heapq.heapify(termlist) #求最大的10个 heapq.nlargest(10,termlist)
使用heapq标准库计算访问次数最多的query,布布扣,bubuko.com
原文:http://blog.csdn.net/yiweis/article/details/20792563