{"id":3553,"date":"2021-04-26T09:21:41","date_gmt":"2021-04-26T03:51:41","guid":{"rendered":"https:\/\/python-programs.com\/?p=3553"},"modified":"2021-11-22T18:43:06","modified_gmt":"2021-11-22T13:13:06","slug":"python-how-to-copy-a-dictionary-shallow-copy-vs-deep-copy","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-how-to-copy-a-dictionary-shallow-copy-vs-deep-copy\/","title":{"rendered":"Python : How to copy a dictionary | Shallow Copy vs Deep Copy"},"content":{"rendered":"

Dictionaries are Python’s implementation of an associative array data structure. A dictionary is a grouping of key-value pairs. Each key pair is represented by a key pair and its associated value.<\/p>\n

A dictionary is defined by a list of key value pairs enclosed in curly braces and separated by a comma. The value of each key is separated by the column \u2018:’.<\/p>\n

It is not possible to sort a dictionary solely to obtain a representation of the sorted dictionary. Dictionary entries are ordered by default, but other data types, such as lists and tuples, are not. As a result, you’ll need an ordered data form like a list\u2014most likely a list of tuples.<\/p>\n

Examples:<\/h3>\n

Input:<\/strong><\/p>\n

dictionary = {'this': 200, 'is':100, 'BTechGeeks':300}<\/pre>\n

Output:<\/strong><\/p>\n

Old dictionary :  {'this': 200, 'is': 100, 'BTechGeeks': 300}\r\nNew dictionary :  {'this': 200, 'is': 100, 'BTechGeeks': 300}<\/pre>\n

Copy a Dictionary:<\/h2>\n

There are several ways to copy a dictionary some of them are:<\/p>\n