I have dictionary in python whose keys are tuples, like:
my-dict={(1,'a'):value1, (1,'b'):value2, (1,'c'):value3, (2,'a'):value4,
(2,'b'):value5,(3,'a'):value6}
I need to access all values whose keys have the same first argument. For example, I need to access
{(1,'a'):value1, (1,'b'):value2, (1,'c'):value3}
because all of them have 1 as the first element of the tuple key. One way is to use a for and if:
for key in my-dict:
if key[0]==1:
do something
However, my actual dictionary and data are very huge and this method takes a lot of time. Is there any other way to efficiently do this?