topkheap.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:kaggle-quora-solution-8th 作者: qqgeogor 项目源码 文件源码
def push(self, elem):
        '''Push new elem to heap

        Args:
                elem ?the elem to add

        Returns:
                if the elem have added to queue
        '''
        if len(self.data) < self.k:
            heapq.heappush(self.data, elem)
            return True
        else:
            topk_small = self.data[0]
            if elem > topk_small:
                heapq.heapreplace(self.data, elem)
                return True
            return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号