I have a need to take an integer value and index into a table of corresponding strings. In this case, contiguous ranges of integers should all map to the same string. Something like (with a non-working dictionary example):
int_dict = { 0 : "String1",
1 : "String2",
2 : "String3",
range(3,15) : "String4",
16 : "String5" };
As expected, using range
here just fails and trying to use lists gives the error TypeError: unhashable type: 'list'
.
Perhaps a dictionary is not the best data structure for this task. My question, then, is how can something like this be easily done? The ranges tend to be quite large, so doing this via manual definition (unless something like range
can be used) is not an option.