Combine dictionaries based on key value
<p>How do I combine the rows of dictionaries having same keys. For instance If I have </p>

<pre><code>my_dict_list = [{'prakash': ['confident']},
 {'gagan': ['good', 'luck']},
 {'jitu': ['gold']},
 {'jitu': ['wins']},
 {'atanu': ['good', 'glory']},
 {'atanu': ['top', 'winner','good']}]
</code></pre>

<p>My objective is to get </p>

<pre><code>my_new_dict_list = [{'prakash': ['confident']},
 {'gagan': ['good', 'luck']},
 {'jitu': ['gold','wins']},
 {'atanu': ['good', 'glory','top', 'winner','good']}]
</code></pre>

<p>How do I do that in Python?</p>

<p>EDIT: The dictionaries in the final list must contain repeated values if present in starting list. </p>

<p>You could loop over the dicts in your list and either insert or append the key-value pairs to a new dict:</p>

<pre><code>my_dict_list = [{'prakash': ['confident']},
                {'gagan': ['good', 'luck']},
                {'jitu': ['gold']},
                {'jitu': ['wins']},
                {'atanu': ['good', 'glory']},
                {'atanu': ['top', 'winner']}]


new_d = {}
for d in my_dict_list:
    for k, v in d.items():
        if k in new_d:
            new_d[k] += v
        else:
            new_d[k] = v
</code></pre>

<p>Then you need to make a list from the result:</p>

<pre><code>l = [{k: v} for k, v in new_d.items()]
# [{'atanu': ['good', 'glory', 'top', 'winner']}, {'gagan': ['good', 'luck']}, {'prakash': ['confident']}, {'jitu': ['gold', 'wins']}]
</code></pre>

<p>You need to be aware that the order of the items in the list may be changed by that.</p>

python