looking for some solutions? You are welcome.

SOLVED: merge two dictionaries with same key values

Rahul Sharma:

I have two dictionaries which consist same keys

a = {'a':[3,2,5],
     'b':[9,8],
     'c':[1,6]}

b = {'b':[7,4],
     'c':[10,11]}

When i merge them the keys of dictionary b replaces the keys of a because of the same name. Here's the merge code I am using

z = dict(list(a.items()) + list(b.items()))

Is there somehow I can keep all the keys, I know dictionaries can't have same key name but I can work with something like this:

a = {'a':[3,2,5],
     'b':[9,8],
     'c':[1,6],
     'b'1:[7,4],
     'c'1:[10,11]}



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent