Event list data structure

Posted on
Tue Jul 19, 2022 2:32 am
Lakshit offline

Event list data structure

I need to implement an event list in python, where each element is an event that has an associated timestamp. 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, however, it doesn't permit to insert of arbitrary items in the list. Hence I feel that perhaps I could execute the occasion list with two unique python

a bisect list containing all the timestamps
a dictionary with the timestamps as the keys and the events as value
Inserting and retrieving is straightforward.

Do you feel that there is a more effective approach?

Posted on
Tue Jul 19, 2022 8:53 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Event list data structure

Just append the new item, then sort the list. Then the item at index 0 is the oldest (assuming you sort on date ascending).

If you sort the list in descending, then you just get the last item (list.pop()) which would be the oldest.

We can help with a more complete answer if you'd give us more specific details (what is an "event" exactly for instance).

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jul 27, 2022 9:04 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Event list data structure

[MODERATOR NOTE]: moved to a more appropriate forum.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 7 guests