# python实现两个字典合并,两个list合并

1.两个字典：a={‘a":1,"b":2,"c":3} b= {‘aa":11,"bb":22,"cc":33}

```>>> a={"a":1,"b":2,"c":3}
>>> b= {"aa":11,"bb":22,"cc":33}
>>> dict(a,**b)
{"a": 1, "aa": 11, "c": 3, "b": 2, "bb": 22, "cc": 33}
>>>```

```>>> a={"a":1,"b":2,"c":3}
>>> b= {"aa":11,"bb":22,"cc":33}
>>> dict(a.items()+b.items())
{"a": 1, "aa": 11, "c": 3, "b": 2, "bb": 22, "cc": 33}
>>>```

```>>> a={"a":1,"b":2,"c":3}
>>> b= {"aa":11,"bb":22,"cc":33}
>>> c={}
>>> c.update(a)
>>> c.update(b)
>>> print c
{"a": 1, "aa": 11, "c": 3, "b": 2, "bb": 22, "cc": 33}
>>> ```

2.两个list合并：

a=[1,2,3,4,5,6] b=[‘a","b","c","d"]

```>>> a=[1,2,3,4,5,6]
>>> b=["a","b","c","d"]
>>> a+b
[1, 2, 3, 4, 5, 6, "a", "b", "c", "d"]
>>> ```

```>>> a=[1,2,3,4,5,6]
>>> b=["a","b","c","d"]
>>> a+=b
>>> print a
[1, 2, 3, 4, 5, 6, "a", "b", "c", "d"]
>>> ```

```>>> a=[1,2,3,4,5,6]
>>> b=["a","b","c","d"]
>>> a.extend(b)
>>> print a
[1, 2, 3, 4, 5, 6, "a", "b", "c", "d"]
>>>```

```>>> a=[1,2,3,4,5,6]
>>> b=["a","b","c","d"]
>>> a.append(b)
>>> print a
[1, 2, 3, 4, 5, 6, ["a", "b", "c", "d"]]
>>>```

```>>> a=[1,2,3,4,5,6]
>>> b=["a","b","c","d"]
>>> a[0:0]=b
>>> print a
["a", "b", "c", "d", 1, 2, 3, 4, 5, 6]
>>> ```