{"id":8495,"date":"2020-05-14T23:28:50","date_gmt":"2020-05-14T17:58:50","guid":{"rendered":"https:\/\/tutorials.eyehunts.com\/?p=8495"},"modified":"2021-08-10T18:57:36","modified_gmt":"2021-08-10T13:27:36","slug":"python-list-copy-function-copyingcloning-a-list-examples","status":"publish","type":"post","link":"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/","title":{"rendered":"Python list copy Function | copying(cloning) a List examples"},"content":{"rendered":"\n<p>The Python list copy method returns a copy of the specified list. It returns a shallow copy of the list.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>What is a shallow copy?  <\/strong><\/p>\n\n\n\n<p><strong>A shallow<\/strong> copy\u00a0is a bit-wise\u00a0copy\u00a0of an object. A new object is created that has an exact\u00a0copy\u00a0of the values in the original object. So, if you need the original list unchanged when the new list is modified, you can use the copy() method. <\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Techniques to shallow copy :<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Using copy.copy()<\/li><li>Using list.copy()<\/li><li>Using slicing<\/li><\/ul>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Syntax<\/strong><\/h3>\n\n\n\n<pre>\nlist.copy()\n<\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Parameter Values<\/strong><\/h3>\n\n\n\n<p>It doesn&#8217;t return any value and doesn&#8217;t modify the original list.<\/p>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Python list copy Function Examples <\/strong><\/h3>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Copy\/clone List example <\/strong><\/h3>\n\n\n\n<p>In the example Copying the list of the fruits. It&#8217;s a copy list\u00a0without changing the <strong>original<\/strong> list.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fruits = &#91;'apple', 'banana', 'cherry', 'orange']\r\n\r\ncopy_fruits = fruits.copy()\r\n\r\nprint(copy_fruits)\r\n<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"522\" height=\"120\" src=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-list-copy-Function.jpg?resize=522%2C120&#038;ssl=1\" alt=\"Python list copy Function\" class=\"wp-image-17822\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Python list copy&nbsp;deep<\/strong><\/h2>\n\n\n\n<p>Techniques to deep copy :<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Using copy.deepcopy()<\/li><li>Using \u201c=\u201d operator<\/li><\/ul>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><em><strong>Example of deep copy<\/strong><\/em><\/p>\n\n\n\n<pre>\nimport copy\n\nlist1 = [1, 2, 3, 4]\n\n# Using deep copy techniques to create a deep copy\nlist2 = list1\nlis3 = copy.deepcopy(list1)\n\n# Adding new element to new lists\nlist2.append(5)\nlis3.append(5)\n\n# Printing lists after adding new element\n# changes reflected in old list\nprint(\"The new list created using copy.deepcopy() : \" + str(list2))\nprint(\"The new list created using = : \" + str(lis3))\nprint(\"The old list  : \" + str(list2))\n\n<\/pre>\n\n\n\n<p><strong>Output: <\/strong><\/p>\n\n\n\n<p>The new list created using copy.deepcopy() : [1, 2, 3, 4, 5]<br>The new list created using = : [1, 2, 3, 4, 5]<br>The old list : [1, 2, 3, 4, 5]<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Copy list&nbsp;by value in Python <\/strong><\/h3>\n\n\n\n<p>A way to copy a list by value:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>new_list = old_list&#91;:]<\/code><\/pre>\n\n\n\n<p>If the list contains objects and you want to copy them as well, use a generic copy.deepcopy():<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import copy\nnew_list = copy.deepcopy(old_list)<\/code><\/pre>\n\n\n\n<div style=\"height:20px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Deep Copy vs Shallow copy<\/strong><\/h3>\n\n\n\n<p>The difference between Deep Copy vs Shallow copy is that Deep copy means if we modify any of the lists, changes are reflected in both lists as they point to the same reference. Whereas in shallow copy, when we add an element in any of the lists, only that list is modified. <\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Q: How to python copy a list&nbsp;of lists?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong> Same as above you can use the copy function to  copy the list of the list:<\/p>\n\n\n\n<pre>\nlist1 = [[1, 2], [3, 4]]\n\nlist2 = list1.copy()\n\nprint(list2)\n\n<\/pre>\n\n\n\n<p><strong>Output<\/strong>: [[1, 2], [3, 4]]<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Q: What are the options to clone or copy a list in Python?<\/strong><\/h3>\n\n\n\n<p><strong>Answer:<\/strong> You can Copy the list in various ways like:<\/p>\n\n\n\n<p>You can use the built-in\u00a0<a href=\"https:\/\/docs.python.org\/3\/library\/stdtypes.html#mutable-sequence-types\"><code>list.copy()<\/code><\/a>\u00a0method (available since Python 3.3):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>new_list = old_list.copy()<\/code><\/pre>\n\n\n\n<p>You can <a href=\"https:\/\/tutorial.eyehunts.com\/\/python\/python-substring-slice-split-string-example\/\" target=\"_blank\" rel=\"noreferrer noopener\">slice<\/a> it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>new_list = old_list&#91;:]<\/code><\/pre>\n\n\n\n<p>You can use the built-in\u00a0<code><a href=\"https:\/\/tutorial.eyehunts.com\/\/python\/python-list-extend-function-adding-all-items-of-a-list-example\/\">list()<\/a><\/code>\u00a0function:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>new_list = list(old_list)<\/code><\/pre>\n\n\n\n<p>You can use generic&nbsp;<a href=\"https:\/\/docs.python.org\/2\/library\/copy.html#copy.copy\"><code>copy.copy()<\/code><\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import copy\nnew_list = copy.copy(old_list)<\/code><\/pre>\n\n\n\n<p>This is a little slower than&nbsp;<code>list()<\/code>&nbsp;because it has to find out the datatype of&nbsp;<code>old_list<\/code>&nbsp;first.<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>If the list contains objects and you want to copy them as well, use generic&nbsp;<a href=\"https:\/\/docs.python.org\/2\/library\/copy.html#copy.deepcopy\"><code>copy.deepcopy()<\/code><\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import copy\nnew_list = copy.deepcopy(old_list)<\/code><\/pre>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p><strong>Complete Example <\/strong><\/p>\n\n\n\n<pre>\nimport copy\n\nclass Foo(object):\n    def __init__(self, val):\n         self.val = val\n\n    def __repr__(self):\n        return 'Foo({!r})'.format(self.val)\n\nfoo = Foo(1)\n\na = ['foo', foo]\nb = a.copy()\nc = a[:]\nd = list(a)\ne = copy.copy(a)\nf = copy.deepcopy(a)\n\n# edit orignal list and instance \na.append('baz')\nfoo.val = 5\n\nprint('original: %r\\nlist.copy(): %r\\nslice: %r\\nlist(): %r\\ncopy: %r\\ndeepcopy: %r'\n      % (a, b, c, d, e, f))\n<\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/\/wp-content\/uploads\/2020\/05\/Python-list-copy-Function.png?resize=430%2C232&#038;ssl=1\" alt=\"Python list copy Function\" class=\"wp-image-8501\" width=\"430\" height=\"232\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Do comment if you have any examples, doubts, and suggestions on this tutorial.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong><br>IDE:\u00a0<a rel=\"noreferrer noopener\" href=\"https:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\">PyCharm<\/a>\u00a02020.1.1 (Community Edition)<br>macOS 10.15.4<br><strong>Python 3.7<\/strong><br>All<strong>\u00a0Python Examples\u00a0are in\u00a0Python\u00a03<\/strong>, so Maybe its different from python 2 or upgraded versions.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>The Python list copy method returns a copy of the specified list. It returns a shallow copy of the list. What is a shallow copy? A shallow copy\u00a0is a bit-wise\u00a0copy\u00a0of an object. A new object is created that has an exact\u00a0copy\u00a0of the values in the original object. So, if you need the original list unchanged&hellip;&nbsp;<a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Python list copy Function | copying(cloning) a List examples<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[30],"tags":[38,83],"post_series":[],"class_list":["post-8495","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-function","tag-python-list"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python list copy Function | copying(cloning) a List examples - EyeHunts<\/title>\n<meta name=\"description\" content=\"Python list copy method returns a copy of the specified list. It returns a shallow copy of the list. You can also use orther method to copying a list in py\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python list copy Function | copying(cloning) a List examples - EyeHunts\" \/>\n<meta property=\"og:description\" content=\"Python list copy method returns a copy of the specified list. It returns a shallow copy of the list. You can also use orther method to copying a list in py\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-14T17:58:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-10T13:27:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-list-copy-Function.jpg\" \/>\n<meta name=\"author\" content=\"Rohit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rohit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/\",\"name\":\"Python list copy Function | copying(cloning) a List examples - EyeHunts\",\"isPartOf\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-list-copy-Function.jpg\",\"datePublished\":\"2020-05-14T17:58:50+00:00\",\"dateModified\":\"2021-08-10T13:27:36+00:00\",\"author\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\"},\"description\":\"Python list copy method returns a copy of the specified list. It returns a shallow copy of the list. You can also use orther method to copying a list in py\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-list-copy-Function.jpg?fit=522%2C120&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-list-copy-Function.jpg?fit=522%2C120&ssl=1\",\"width\":522,\"height\":120},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorial.eyehunts.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python list copy Function | copying(cloning) a List examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\",\"url\":\"https:\/\/tutorial.eyehunts.com\/\",\"name\":\"Tutorial\",\"description\":\"By EyeHunts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\",\"name\":\"Rohit\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"contentUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"caption\":\"Rohit\"},\"description\":\"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.\",\"url\":\"https:\/\/tutorial.eyehunts.com\/author\/rohit\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python list copy Function | copying(cloning) a List examples - EyeHunts","description":"Python list copy method returns a copy of the specified list. It returns a shallow copy of the list. You can also use orther method to copying a list in py","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/","og_locale":"en_US","og_type":"article","og_title":"Python list copy Function | copying(cloning) a List examples - EyeHunts","og_description":"Python list copy method returns a copy of the specified list. It returns a shallow copy of the list. You can also use orther method to copying a list in py","og_url":"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/","og_site_name":"Tutorial","article_published_time":"2020-05-14T17:58:50+00:00","article_modified_time":"2021-08-10T13:27:36+00:00","og_image":[{"url":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-list-copy-Function.jpg","type":"","width":"","height":""}],"author":"Rohit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rohit","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/","url":"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/","name":"Python list copy Function | copying(cloning) a List examples - EyeHunts","isPartOf":{"@id":"https:\/\/tutorial.eyehunts.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/#primaryimage"},"image":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-list-copy-Function.jpg","datePublished":"2020-05-14T17:58:50+00:00","dateModified":"2021-08-10T13:27:36+00:00","author":{"@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1"},"description":"Python list copy method returns a copy of the specified list. It returns a shallow copy of the list. You can also use orther method to copying a list in py","breadcrumb":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/#primaryimage","url":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-list-copy-Function.jpg?fit=522%2C120&ssl=1","contentUrl":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-list-copy-Function.jpg?fit=522%2C120&ssl=1","width":522,"height":120},{"@type":"BreadcrumbList","@id":"https:\/\/tutorial.eyehunts.com\/python\/python-list-copy-function-copyingcloning-a-list-examples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorial.eyehunts.com\/"},{"@type":"ListItem","position":2,"name":"Python list copy Function | copying(cloning) a List examples"}]},{"@type":"WebSite","@id":"https:\/\/tutorial.eyehunts.com\/#website","url":"https:\/\/tutorial.eyehunts.com\/","name":"Tutorial","description":"By EyeHunts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1","name":"Rohit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/","url":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","contentUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","caption":"Rohit"},"description":"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.","url":"https:\/\/tutorial.eyehunts.com\/author\/rohit\/"}]}},"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":22078,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-copy-dictionary-copy-function\/","url_meta":{"origin":8495,"position":0},"title":"Python copy dictionary | copy() function","author":"Rohit","date":"November 17, 2021","format":false,"excerpt":"Use copy() method to copy the dictionary in Python. This method returns a copy (shallow copy) of the dictionary and doesn\u2019t take any parameters. dict.copy() Example how to copy a dictionary in Python Simple example code. original = {1: 'A', 2: 'B'} copy_dict = original.copy() print(copy_dict) Output: If you need\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python copy dictionary","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/Python-copy-dictionary.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":22415,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-copy-dictionary-into-another-example-code\/","url_meta":{"origin":8495,"position":1},"title":"Python copy dictionary into another | Example code","author":"Rohit","date":"November 23, 2021","format":false,"excerpt":"Use the assignment operator to shallow copy a dictionary into another in Python. But if you want to use deep copy then use the deepcopy() method. Example copy a dictionary into another in Python Simple example code assign dict2 = dict1, not making a copy of dict1, it results in\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python copy dictionary into another","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/Python-copy-dictionary-into-another.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":8351,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-list-array-methods-remove-insert-pop-reverse-count-sort-append-copy\/","url_meta":{"origin":8495,"position":2},"title":"Python list (Array) methods | remove, insert, pop, reverse, count, sort, append, copy","author":"Rohit","date":"May 16, 2020","format":false,"excerpt":"Python List has built-in methods that you can use for important operations in the list data structure. Python List function is changed from time to time in different versions. The most basic and important data structure in Python is the\u00a0List. In this tutorial, you will learn about the list methods\u00a0of\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/05\/Python-list-Array-methods-.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/05\/Python-list-Array-methods-.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/05\/Python-list-Array-methods-.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2020\/05\/Python-list-Array-methods-.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":18599,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-dictionary-methods\/","url_meta":{"origin":8495,"position":3},"title":"Python dictionary methods","author":"Rohit","date":"July 17, 2023","format":false,"excerpt":"Python dictionary methods are built-in functions that can be called on dictionary objects to perform various operations. These methods provide a way to manipulate, access, and modify dictionaries in Python. Some common dictionary methods include: clear(): Removes all key-value pairs from the dictionary. my_dict.clear() copy(): Returns a shallow copy of\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/07\/Python-dictionary-methods.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/07\/Python-dictionary-methods.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/07\/Python-dictionary-methods.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/07\/Python-dictionary-methods.jpg?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":34323,"url":"https:\/\/tutorial.eyehunts.com\/python\/help-and-dir-function-in-python\/","url_meta":{"origin":8495,"position":4},"title":"help() and dir() function in Python","author":"Rohit","date":"November 22, 2022","format":false,"excerpt":"Python help() function returns the Python documentation of a particular object, method, attributes, etc, and dir() shows a list of attributes for the object passed in as an argument. dir() Returns all functions that are available in a particular Module help() Gives the information about the function in that particular\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/11\/help-and-dir-function-in-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":32796,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-set-copy-method\/","url_meta":{"origin":8495,"position":5},"title":"Python Set copy() | Method","author":"Rohit","date":"September 14, 2022","format":false,"excerpt":"Python Set copy() method is used to copy the set but it's a shallow copy. That means if we modify something in the copied set, changes are not reflected back in the original set. set.copy() Use \u201c=\u201d to copy a set, and modify the copied set, the changes are also\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python Set copy()  Method","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2022\/09\/Python-Set-copy-Method.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/8495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/comments?post=8495"}],"version-history":[{"count":1,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/8495\/revisions"}],"predecessor-version":[{"id":17823,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/8495\/revisions\/17823"}],"wp:attachment":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/media?parent=8495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/categories?post=8495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/tags?post=8495"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/post_series?post=8495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}