>>> from heapq import heappush
>>> heap = []
>>> heappush(heap,(0,{"k":0}))
>>> heappush(heap,(0,{"k":1}))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: '<' not supported between instances of 'dict' and 'dict'
这在Python2官方堆文档和Python3中提到,文档建议DIY实现
heapq
以减轻此问题。为什么会发生这种情况?既然
heapq
是一个非常古老的库,为什么这样的冲突没有得到解决?是否存在性能/其他问题?为什么我们不能将像keep_old、keep_any
这样的参数作为该库的功能提供?
keep_new
)。那个错误信息非常误导! - xxbidiao