2
我有這樣的代碼:開關元件中的PriorityQueue
q = PriorityQueue()
a = ((1, 1), 10, 0)
q.put(a)
newTuple = ((1,1), 8, 0)
res = any(newTuple[0] in item for item in q.queue) #res = true
目前,我檢查是否newTuple [0](即(1,1))在時Queue任何元組存在。 我想改變代碼,以便它檢查newTuple [0]是否在隊列中,如果它確實是(並因此與某個元組'a'相關聯),則替換隊列中的該元組'a'如果newTuple [1](即8)小於a [1](即10),則使用newTuple。
這可能嗎?
如果您打算讓我失望,請告訴我我該如何改進? –
據我所知'PriorityQueue'環繞'heapq',當然你可以改變'q.queue',但是你需要重新heapify它。爲什麼不直接使用'heapq'? – georgexsh