Combine Python dictionaries that have the same Key name
python
Solution
When you are sure, that the key names are equal in both dictionaries:
clientlist = dict([(k, [clientList[k], recordlist[k]]) for k in clientList])
like here:
>>> a = {1:1,2:2,3:3}
>>> b = {1:11,2:12,3:13}
>>> c = dict([(k,[a[k],b[k]]) for k in a])
>>> c
{1: [1, 11], 2: [2, 12], 3: [3, 13]}
Problem
I have two separate Python List that have common key names in their respective dictionary. The second list called `recordList` has multiple dictionaries with the same key name that I want to append the first list `clientList`. Here are examples lists: ``` clientList = [{'client1': ['c1','f1']}, {'client2': ['c2','f2']}] recordList = [{'client1': {'rec_1':['t1','s1']}}, {'client1': {'rec_2':['t2','s2']}}] ``` So the end result would be something like this so the records are now in a new list of multiple dictionaries within the `clientList`. ``` clientList = [{'client1': [['c1','f1'], [{'rec_1':['t1','s1']},{'rec_2':['t2','s2']}]]}, {'client2': [['c2','f2']]}] ``` Seems simple enough but I'm struggling to find a way to iterate both of these dictionaries using variables to find where they match.