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>a minimalist approach using <code>defaultdict</code>:</p>

<pre><code>from collections import defaultdict

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

merged_dict = defaultdict(list)
for d in my_dict_list:
    for key, value in d.items():
        merged_dict[key].extend(value)
result = [{key:value} for key, value in merged_dict.items()]

print(result)
</code></pre>

<p><strong>Output</strong></p>

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

python