Question: I have two dictionaries as follows:

`D1={'a':1,'b':2,'c':3}`

and 

`D2={'b':2,'c':3,'d':1}`

I want to merge these two dictionaries and the result should be as follows:

`D3={'a':1,'b':2,'c':3,'b':2,'c':3,'d':1}`

how can I achieve this in python?

Answer: 
You may want to try:

```
D3 = {}
D3.update(D1)
D3.update(D2)

```

Here, we're creating an empty dictionary `D3` first, then update it from the two other dictionaries.

Note that you need to be careful with the order of the updates: if `D2` shares some keys with `D1`, the code above will overwrite the corresponding entries of `D1` with those of `D2`.

Note as well that the keys will **not** be repeated. The example you give `D3={a:1,b:2,c:3,b:2,c:3,d:1}` is not a valid dictionary.
Dictionaries by definition can't have duplicate keys, so "merging" dictionaries will actually give the following result (note the order is arbitrary):

```
{'a': 1, 'b': 2, 'c': 3, 'd': 1}

```

You can create a clone of one of the dictionaries and merge the entries from the other into it:

```
D3 = dict(D1)
D3.update(D2)

```

or you can create a new dictionary from the concatenation of the (key, value) tuples from each input dictionary:

```
D3 = dict(D1.items() + D2.items())

```

If you really want multiple values for duplicate keys, you need something like a list of values for each key:

```
from itertools import groupby
dict(( (key, [v for k, v in group]) for key, group in groupby(sorted(D1.items() + D2.items()), lambda x: x[0])))

```