Reputation: 1467
I'm working on an application where I will need to maintain an object's trajectory. Basically, I'd like to have something like a sorted dictionary where the keys are times, and the values are positions. In addition, I'll be doing linear interpolation between existing entries. I've played a little bit with SortedDictionary in Grant Jenks's SortedContainers library, and it does a lot of what I want, but I'm wondering if there are solutions out there that are an even better fit? Thanks in advance for any suggestions.
Upvotes: 4
Views: 3507
Reputation: 36662
If your time interval is reliably constant, a list or of course a numpy array can be used.
Otherwise, you could look into ordered dictionaries in the collections module (std lib)
https://docs.python.org/2/library/collections.html (Python 2)
class collections.OrderedDict([items])
Return an instance of a dict subclass, supporting the usual dict
methods. An OrderedDict is a dict that remembers the order that keys were first inserted. If a new entry overwrites an existing entry, the original insertion position is left unchanged. Deleting an entry and reinserting it will move it to the end.
Upvotes: 1