In Python, I need a dictionary object which looks like:
{\'a\': 10, \'b\': 20, \'c\': 10, \'d\': 10, \'e\': 20}
I\'ve been able to get th
I would say what you have is very simple, you could slightly improve it to be:
my_dict = dict.fromkeys(['a', 'b', 'c'], 10)
my_dict.update(dict.fromkeys(['b', 'e'], 20))
If your keys are tuple you could do:
>>> my_dict = {('a', 'c', 'd'): 10, ('b', 'e'): 20}
>>> next(v for k, v in my_dict.items() if 'c' in k) # use .iteritems() python-2.x
10
This is, of course, will return first encountered value, key for which contains given element.