In Python, heapq.heapify doesn't take cmp or key functions as arguments like sorted does

前端 未结 5 764
离开以前
离开以前 2020-12-10 10:04

I\'m using python2.6. Is it available in higher version of python?
Else is there any other way I can maintain priority queues for list of objects of non-trivial classes?

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-10 11:01

    Well, this is terrible and awful and you definitely shouldn't do it… But it looks like the heapq module defines a cmp_lt function, which you could monkey patch if you really wanted a custom compare function.

提交回复
热议问题