python中字典的复制
1、
>>> test1 = dict(key1="xxx",key2="aaa",key3=100,key="abc")
>>> test1
{'key1': 'xxx', 'key2': 'aaa', 'key3': 100, 'key': 'abc'}
>>> type(test1)
<class 'dict'>
>>> len(test1)
4
>>> test2={}
>>> for i,j in test1.items():
test2[i] = j
>>> test2
{'key1': 'xxx', 'key2': 'aaa', 'key3': 100, 'key': 'abc'}
>>> test1
{'key1': 'xxx', 'key2': 'aaa', 'key3': 100, 'key': 'abc'}
2、
>>> test1 = {"key1":"aaa","key2":"bbb","key3":"ccc"}
>>> test1
{'key1': 'aaa', 'key2': 'bbb', 'key3': 'ccc'}
>>> test2 = test1.copy()
>>> test2
{'key1': 'aaa', 'key2': 'bbb', 'key3': 'ccc'}