Basically, I need to make a lookup table with non-consecutive integer IDs. I'm wondering whether, in terms of lookup speed, I'm generally better off using a dict with integer keys anyway, or using a very long list with a lot of empty indices. It seems to me that a list might still be faster, as Python should know exactly where to look, but I'm wondering if there are any backend processes with the dict to compensate and whether the additional memory requirements for those empty list slots would negate the (probably) more easily traversed list's speed gains. Are there any alternatives to lists and dicts that might be better suited to this?
I have seen this question, but it doesn't totally answer mine: Dictionary access speed comparison with integer key against string key
ETA: I'm implementing lookup tables like this twice in my program. One instance sees a max id of 5,000 with 70-100 objects populated; the other has a max id of 750 with 20-30 populated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With