Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top