Copy a dictionary : Dictionary Copy « Dictionary « Python






Copy a dictionary

Copy a dictionary

L = [1,2,3]
D = {'a':1, 'b':2}

A = L[:]              # instead of: A = L (or list(L))
B = D.copy()          # instead of: B = D

A[1] = 'Ni'
B['c'] = 'spam'

print L, D

print A, B

           
       








Related examples in the same category

1.Dictionary copyDictionary copy
2.Dictionary deep copyDictionary deep copy