For example, if I have got millions of records inside a dictionary with the form of
{(1,2):3,(2,3):4,(3:2):5...xmillion}
That’s a tuple as a key and with a corresponding value
What I would like to do is get the data of which the value of tuple[1] = 2
One of my approach is
for item, value in dict.iteritems():
if item[1] == 2:
Do operations here...
This is a slow approach, is there a better algorithm for doing this to make it fast?
Like.. so I don’t have to go through million of the items
In a dictionary of tuples as key, you would have to iterate through all the keys to find
those with
key[1] == 2. There is no other alternative to solving the problem.