I don’t think this is a duplicate, but I just might not be using the correct terminology in my searching. My apologies if this is the case.
What I have is a dictionary mapping a tuple (custom object, string) to a float. To be exact then, it is a 2-tuple. What I am trying to do is get back a representation of all entries in the dictionary that match on the custom object.
Example:
mydict[(co1, 'hello')] = 0.01
mydict[(co2, 'bye')] = 0.02
Where co1 and co2 are supposed to represent two distinct custom objects. I want to find all entries that contain co1 (it’s logical equivalent) in the tuple which is the key.
So my question then is how to reduce this 2_tuple=>float dictionary down to a string=>float dictionary when the string is the unique (non-matched) tuple.
What I have tried:
for custom in custom_object:
for k, v in mydict.iteritems():
if custom in k:
#store this particular entry into another data structure or otherwise process
You can use unpacking in a comprehension:
From Python 2.7: