First, this question is not a duplicate of Most efficient method to get key for a value in a dict for the inquirer there asked about python and also because I want to discuss if solution given below makes sense and if it is fine to go about such a problem.
So, let's suppose, I have following a following datastructure:
{
"one" : "1",
"two" : "2",
.
.
"hundred thousand" : "100000"
}
Now, I want to able to get key against a particular value (assuming that I will not have same values for different keys). One solution is to get key by iterating the data but how efficient can become our code if we structure our data as:
data = [
{
"one" : "1",
"two" : "2",
.
.
"hundred thousand" : "100000"
},
{
"1" : "one",
"2" : "two",
.
.
"100000" : "hundred thousand"
}
]
So, now data[0]."two"
can be used to get value of two. But, let's suppose there is a scenario in which I know the value as 999 and I want to know it's key so to get its key I will do data[1]."999"
i.e. I will use the reversed data in data[1].
This solution is perhaps faster than iterating over data to find right key. What do you think?