I am trying to combine three dictionaries, all of which have the same keys, as well as lists of values ββor single values.
one={'a': [1, 2], 'c': [5, 6], 'b': [3, 4]} two={'a': [2.4, 3.4], 'c': [5.6, 7.6], 'b': [3.5, 4.5]} three={'a': 1.2, 'c': 3.4, 'b': 2.3}
I need all the elements in the values ββto be added to the same list.
result={'a': [1, 2, 2.4, 3.4, 1.2], 'c': [5, 6, 5.6, 7.6, 2.3], 'b': [3, 4, 3.5, 4.5, 3.4]}
I tried a few things, but most put the values ββin nested lists. For instance.
out=dict((k, [one[k], two.get(k), three.get(k)]) for k in one) {'a': [[1, 2], [2.4, 3.4], 1.2], 'c': [[5, 6], [5.6, 7.6], 3.4], 'b': [[3, 4], [3.5, 4.5], 2.3]}
I tried updating it by doing the following:
out.update((k, [x for x in v]) for k,v in out.iteritems())
but the results were exactly the same. I tried just adding lists, but since the third dictionary has only float, I could not do this.
check=dict((k, [one[k]+two[k]+three[k]]) for k in one)
So, I tried to add lists in values ββone and two first, and then add value three. Adding lists worked fine, but then when I tried to add a float from the third dictionary, all of a sudden the whole value moved to "None"
check=dict((k, [one[k]+two[k]]) for k in one) {'a': [[1, 2, 2.4, 3.4]], 'c': [[5, 6, 5.6, 7.6]], 'b': [[3, 4, 3.5, 4.5]]} new=dict((k, v.append(three[k])) for k,v in check.items()) {'a': None, 'c': None, 'b': None}