Assuming a dictionary where the keys are tuples:
D = {
('a','b') : 1,
('x','y','z') : 2
}
How can I split each tuple-key into separate keys with the same value:
N = {
'a' : 1, 'b' : 1,
'x' : 2, 'y' : 2, 'z' : 2
}
In a single dictionary comprehension. I've drafted up the following line, but I'm wondering if it's possible to shorten it and not create a proxy value list of the same length as the key tuple.
N = { k:v for s in ( zip(keys,[value]*len(keys)) for keys,value in D.items() ) for k,v in s }