문제

I need to implement an event list in python, where each element is an event that has an associated timestamps. The actions that I need to perform are essentially two: inserting in the right order (decreasing timestamps), and retrieving the event with the smaller start time.

I am aware of the bisect module, but it doesn't allow to insert arbitrary items in the list. For this reason I think that maybe I could implement the event list with two different python data structures:

  • a bisect list containing all the timestamps
  • a dictionary with the timestamps as the keys ans the events as value

Inserting and retrieving are straightforward.

Do you think that there is a more efficient approach?

도움이 되었습니까?

해결책

You can either go with heap queue, as @Bogdan suggests, or you can use sched for more advance purposes.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top