Mapping with continguous ranges of keys
steve+python at pearwood.info
Thu Dec 15 12:06:25 EST 2016
I have some key:value data where the keys often are found in contiguous
ranges with identical values. For example:
# same for keys 4 through 99
So in this case, the keys 1 through 100, plus 105, all have the same value.
I have about a million or two keys, with a few hundred or perhaps a few
thousand distinct values. The size of each contiguous group of keys with
the same value can vary from 1 to perhaps a hundred or so.
Has anyone dealt with data like this and could give a recommendation of the
right data structure to use?
The obvious way is to explicitly list each key, in a regular dict. But I
wonder whether there are alternatives which may be better (faster, more
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.
More information about the Python-list