{"id":21734,"date":"2022-03-30T14:02:52","date_gmt":"2022-03-30T08:32:52","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=21734"},"modified":"2022-03-30T14:02:55","modified_gmt":"2022-03-30T08:32:55","slug":"python-copy-list","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/python-copy-list\/","title":{"rendered":"Ways to Copy List in Python"},"content":{"rendered":"\n<p>There will be times when you might want to copy a list in Python. For instance, if you&#8217;re going to keep the original list untouched. Instead, you may want to perform some operations on the copied list or maybe some other operations. <\/p>\n\n\n\n<p>The following article covers the difference between shallow and deep copy, ways to copy a list and a nested list in Python.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#Shallow_Vs_Deep_Copy_in_Python\" >Shallow Vs. Deep Copy in Python<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#Immutability_and_mutability_in_Python\" >Immutability and mutability in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#Shallow_Copy\" >Shallow Copy<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#Deep_Copy\" >Deep Copy<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#List_Copy_Methods_in_Python\" >List Copy Methods in Python<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#Using_the_list_method\" >Using the list method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#Using_the_%E2%80%98_%E2%80%98_operator\" >Using the &#8216; = &#8216; operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#Using_the_list_slicing\" >Using the list slicing<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#Using_the_list_comprehension\" >Using the list comprehension<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#Using_the_extend_method\" >Using the extend method<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#Using_the_append_method\" >Using the append method<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#Copying_a_list_multiple_times\" >Copying a list multiple times<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#Using_the_%E2%80%98_%E2%80%98_operator-2\" >Using the &#8216; * &#8216; operator<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#Using_the_list_comprehension-2\" >Using the list comprehension<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#Using_the_itertools_repeat_method\" >Using the itertools repeat method<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#FAQs_on_Copy_List_in_Python\" >FAQs on Copy List in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#Trending_Python_Articles\" >Trending Python Articles<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-shallow-vs-deep-copy-in-python\"><span class=\"ez-toc-section\" id=\"Shallow_Vs_Deep_Copy_in_Python\"><\/span>Shallow Vs. Deep Copy in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Before establishing the difference between shallow and deep copy, we would like to talk about immutability and mutability in Python. <\/p>\n\n\n\n<p>As the name suggests,<strong> immutable objects<\/strong> can&#8217;t be altered, and therefore, Python will instead create a new object when the value of such object is modified. However, <strong>mutable objects<\/strong> can be altered. <\/p>\n\n\n\n<p><strong>Immutable objects:<\/strong> int, string, tuple<\/p>\n\n\n\n<p><strong>Mutable objects: <\/strong>list, sets, dictionary <\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-immutability-and-mutability-in-python\"><span class=\"ez-toc-section\" id=\"Immutability_and_mutability_in_Python\"><\/span>Immutability and mutability in Python<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# int objects in python are immutable\na = 10\nb = a\na += 10\n\nprint(f&quot;Values: a = {a}, b = {b}&quot;)\nprint(f&quot;{id(a) == id(b)}&quot;)\n\n# However, list objects in python are mutable\nl1 = &#x5B;&#x5B;1],&#x5B;2],&#x5B;3]]\nl2 = l1\nl1&#x5B;0]&#x5B;0] = 10\n\nprint(f&quot;\\nValues: l1 = {l1}, l2 = {l2}&quot;)\nprint(f&quot;{id(l1) == id(l2)}&quot;)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"173\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-62-1024x173.png\" alt=\"Immutability and mutability\" class=\"wp-image-21744\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-62-1024x173.png 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-62-300x51.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-62-768x130.png 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-62-1536x260.png 1536w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-62.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Immutability and mutability<\/figcaption><\/figure>\n\n\n\n<p><strong>Python provides two ways to copy a list; these are:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Shallow copy<\/strong><\/li><li><strong>Deep copy<\/strong><\/li><\/ul>\n\n\n\n<p>Let&#8217;s understand the difference between them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-shallow-copy\"><span class=\"ez-toc-section\" id=\"Shallow_Copy\"><\/span>Shallow Copy<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>In <strong>shallow copy<\/strong>, an object is created that then gets populated with the references of the items of the original list. One level of <span style=\"text-decoration: underline;\"><strong><a href=\"http:\/\/www.pythonpool.com\/deep-learning-opportunities\/\" target=\"_blank\" rel=\"noreferrer noopener\">deep<\/a><\/strong><\/span> copying occurs in shallow copy. A shallow copy of the list is created using the copy method of the copy module. However, there are other ways too. Let&#8217;s understand this using an example.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport copy\n\nlist1 = &#x5B;&#x5B;1,2,3],&#x5B;4,5,6],&#x5B;7,8,9]]\nlist2 = copy.copy(list1)\n\nlist1&#x5B;0]&#x5B;0] = 101\nprint(f&quot;list1:{list1}\\nlist2:{list2}&quot;)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"111\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-71-1024x111.png\" alt=\"Shallow copy a list\" class=\"wp-image-21773\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-71-1024x111.png 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-71-300x33.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-71-768x83.png 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-71-1536x167.png 1536w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-71.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>A shallow copy of a list<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-deep-copy\"><span class=\"ez-toc-section\" id=\"Deep_Copy\"><\/span>Deep Copy<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>While in the case of <strong>deep copy<\/strong>, it recursively copies the items found in the original list to the new object. This way, it creates a clone\/copy of the original list. A deep copy of the list can be created using the deep copy method of the copy module.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport copy\n\nlist1 = &#x5B;&#x5B;1,2,3],&#x5B;4,5,6],&#x5B;7,8,9]]\nlist2 = copy.deepcopy(list1)\n\nlist1&#x5B;0]&#x5B;0] = 101\nprint(f&quot;list1:{list1}\\nlist2:{list2}&quot;)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"121\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-63-1024x121.png\" alt=\"Deep copy a list\" class=\"wp-image-21749\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-63-1024x121.png 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-63-300x35.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-63-768x90.png 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-63-1536x181.png 1536w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-63.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Deep copy a list<\/figcaption><\/figure>\n\n\n\n<p>You can read more about shallow and deep copy operations from <strong><a href=\"https:\/\/docs.python.org\/3\/library\/copy.html\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a><\/strong>.<\/p>\n\n\n<div class=\"monsterinsights-inline-popular-posts monsterinsights-inline-popular-posts-juliett monsterinsights-popular-posts-styled\" ><div class=\"monsterinsights-inline-popular-posts-image\"><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-cant-compare-datetime-datetime-to-datetime-date\/\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_.webp 1200w \" alt=\"[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date\" \/><\/a><\/div><div class=\"monsterinsights-inline-popular-posts-text\"><span class=\"monsterinsights-inline-popular-posts-label\" >Trending<\/span><span class=\"monsterinsights-inline-popular-posts-border\" ><\/span><div class=\"monsterinsights-inline-popular-posts-post\"><a class=\"monsterinsights-inline-popular-posts-title\"  href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-cant-compare-datetime-datetime-to-datetime-date\/\">[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date<\/a><\/div><\/div><\/div><p><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-list-copy-methods-in-python\"><span class=\"ez-toc-section\" id=\"List_Copy_Methods_in_Python\"><\/span>List Copy Methods in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-the-list-method\"><span class=\"ez-toc-section\" id=\"Using_the_list_method\"><\/span>Using the list method<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>List constructor of Python can create a copy of a list.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nlist1 = &#x5B;&#x5B;2,4,6],&#x5B;3,6,9],&#x5B;'erwin','levi','hange']]\nlist2 = list(list1)\n\nprint(f&quot;list1:{list1}\\nlist2:{list2}&quot;)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"111\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-69-1024x111.png\" alt=\"Copying a list using the list method\" class=\"wp-image-21769\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-69-1024x111.png 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-69-300x33.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-69-768x83.png 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-69-1536x167.png 1536w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-69-2048x222.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Copying a list using the list method<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-the-operator\"><span class=\"ez-toc-section\" id=\"Using_the_%E2%80%98_%E2%80%98_operator\"><\/span>Using the &#8216; = &#8216; operator<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The assignment = operator can create a copy of a list.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nlist1 = &#x5B;&#x5B;21,24,66],&#x5B;233,26,69],&#x5B;'kevin', 'ben']]\nlist2 = list1\n\nprint(f&quot;list1:{list1}\\nlist2:{list2}&quot;)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"111\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-68-1024x111.png\" alt=\"Copying a list using the ' = ' operator\" class=\"wp-image-21768\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-68-1024x111.png 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-68-300x33.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-68-768x83.png 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-68-1536x167.png 1536w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-68-2048x222.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Copying a list using the &#8216; = &#8216; operator<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-the-list-slicing\"><span class=\"ez-toc-section\" id=\"Using_the_list_slicing\"><\/span>Using the list slicing<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Python&#8217;s list slicing is used to create a copy of a list.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nlist1 = &#x5B;&#x5B;1,2,3],&#x5B;4,5,6],&#x5B;7,8,9]]\nlist2 = list1&#x5B;:]\n\nprint(f&quot;list1:{list1}\\nlist2:{list2}&quot;)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"111\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-67-1024x111.png\" alt=\"Copying a list using the list slicing\" class=\"wp-image-21766\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-67-1024x111.png 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-67-300x33.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-67-768x83.png 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-67-1536x167.png 1536w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-67.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Copying a list using the list slicing<\/figcaption><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"h-copy-list-except-for-the-last-element\">Copy list except for the last element<\/h4>\n\n\n\n<p>In order to get a list without the last element, you can do the following:<\/p>\n\n\n\n<p>list1 = [[1,2,3],[4,5,6],[7,8,9]]<br>list2 = list1[:-1]<\/p>\n\n\n\n<p>print(f&#8221;list1:{list1}\\nlist2:{list2}&#8221;)<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-75-1024x120.png\" alt=\"Copying a list except for the last element, using the list slicing\" class=\"wp-image-21811\" width=\"705\" height=\"82\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-75-1024x120.png 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-75-300x35.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-75-768x90.png 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-75-1536x180.png 1536w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-75.png 1860w\" sizes=\"(max-width: 705px) 100vw, 705px\" \/><figcaption>Copying a list except for the last element, using the list slicing<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-the-list-comprehension\"><span class=\"ez-toc-section\" id=\"Using_the_list_comprehension\"><\/span>Using the list comprehension<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Similarly, Python&#8217;s list comprehension is used to create a copy of a list.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nlist1 = &#x5B;&#x5B;2,4,6],&#x5B;3,6,9],&#x5B;4,8,12]]\nlist2 = &#x5B;item for item in list1]\n\nprint(f&quot;list1:{list1}\\nlist2:{list2}&quot;)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"111\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-70-1024x111.png\" alt=\"Copying a list using list comprehension\" class=\"wp-image-21770\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-70-1024x111.png 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-70-300x33.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-70-768x83.png 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-70-1536x167.png 1536w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-70.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Copying a list using list comprehension<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_the_extend_method\"><\/span>Using the extend method<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Python&#8217;s extend method can create a copy of a list.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nlist1 = &#x5B;&#x5B;2,4,6],&#x5B;3,6,9],&#x5B;4,8,12]]\nlist2 = &#x5B;]\nlist2.extend(list1)\n\nprint(f&quot;list1:{list1}\\nlist2:{list2}&quot;)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"111\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-72-1024x111.png\" alt=\"Copying a list using the extend method\" class=\"wp-image-21775\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-72-1024x111.png 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-72-300x33.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-72-768x83.png 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-72-1536x167.png 1536w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-72.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Copying a list using the extend method<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-the-append-method\"><span class=\"ez-toc-section\" id=\"Using_the_append_method\"><\/span>Using the append method<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Similarly, Python&#8217;s <span style=\"text-decoration: underline;\"><strong><a href=\"http:\/\/www.pythonpool.com\/python-extend-vs-append\/\" target=\"_blank\" rel=\"noreferrer noopener\">append<\/a><\/strong><\/span> method can also create a copy of a list.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nlist1 = &#x5B;&#x5B;12,14,6],&#x5B;13,16,19],&#x5B;14,81,112]]\nlist2 = &#x5B;]\nlist2.append(list1)\n\nprint(f&quot;list1:{list1}\\nlist2:{list2}&quot;)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"111\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-74-1024x111.png\" alt=\"Copying a list using append method\" class=\"wp-image-21779\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-74-1024x111.png 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-74-300x33.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-74-768x83.png 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-74-1536x167.png 1536w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/1-74-2048x222.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Copying a list using the append method<\/figcaption><\/figure>\n\n\n<div class=\"monsterinsights-inline-popular-posts monsterinsights-inline-popular-posts-golf monsterinsights-popular-posts-styled\" ><div class=\"monsterinsights-inline-popular-posts-text\"><span class=\"monsterinsights-inline-popular-posts-label\" >Popular now<\/span><span class=\"monsterinsights-inline-popular-posts-border\" ><\/span><span class=\"monsterinsights-inline-popular-posts-border-2\" ><\/span><div class=\"monsterinsights-inline-popular-posts-post\"><a class=\"monsterinsights-inline-popular-posts-title\"  href=\"https:\/\/www.pythonpool.com\/fixed-nameerror-name-unicode-is-not-defined\/\">[Fixed] nameerror: name Unicode is not defined<\/a><\/div><\/div><\/div><p><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-copying-a-list-multiple-times\"><span class=\"ez-toc-section\" id=\"Copying_a_list_multiple_times\"><\/span>Copying a list multiple times<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We can easily create multiple copies of a list. Let&#8217;s go through the different methods:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-the-operator-1\"><span class=\"ez-toc-section\" id=\"Using_the_%E2%80%98_%E2%80%98_operator-2\"><\/span>Using the &#8216; * &#8216; operator<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>This method creates a shallow copy.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nl1 = &#x5B;&#x5B;1,2,3,4,5]]\nnum_of_copies = int(input(&quot;Enter the number of copies:&quot;))\nl2 = l1 * num_of_copies\nprint(l2)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"118\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/2-38-1024x118.png\" alt=\"Copying a list multiple times, using ' * ' operator\" class=\"wp-image-21828\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/2-38-1024x118.png 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/2-38-300x35.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/2-38-768x89.png 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/2-38-1536x177.png 1536w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/2-38-2048x236.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Copying a list multiple times, using the &#8216; * &#8216; operator<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-the-list-comprehension-1\"><span class=\"ez-toc-section\" id=\"Using_the_list_comprehension-2\"><\/span>Using the list comprehension<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nl1 = &#x5B;1,2,3,4,5]\nnum_of_copies = int(input(&quot;Enter the number of copies:&quot;))\nl2 = &#x5B;l1 for _ in range(num_of_copies)]\nprint(l2)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"118\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/3-19-1024x118.png\" alt=\"Copying a list multiple times, using list comprehension\" class=\"wp-image-21827\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/3-19-1024x118.png 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/3-19-300x35.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/3-19-768x89.png 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/3-19-1536x177.png 1536w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/3-19-2048x236.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Copying a list multiple times, using list comprehension<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-using-the-itertools-repeat-method\"><span class=\"ez-toc-section\" id=\"Using_the_itertools_repeat_method\"><\/span>Using the itertools repeat method<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nfrom itertools import repeat\n\nnum_of_copies = int(input(&quot;Enter the number of copies:&quot;))\nl = &#x5B;1,2,3,4]\nl_copy = list(repeat(l,num_of_copies))\nprint(l_copy)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"118\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/4-15-1024x118.png\" alt=\"Copying a list multiple times, using itertools repeat method\" class=\"wp-image-21830\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/4-15-1024x118.png 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/4-15-300x35.png 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/4-15-768x89.png 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/4-15-1536x177.png 1536w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/4-15-2048x236.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>Copying a list multiple times, using itertools repeat method<\/figcaption><\/figure>\n\n\n<div class=\"monsterinsights-inline-popular-posts monsterinsights-inline-popular-posts-beta monsterinsights-popular-posts-styled\" ><div class=\"monsterinsights-inline-popular-posts-image\"><a href=\"https:\/\/www.pythonpool.com\/solved-runtimeerror-cuda-error-invalid-device-ordinal\/\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal.webp 1200w \" alt=\"[Solved] runtimeerror: cuda error: invalid device ordinal\" \/><\/a><\/div><div class=\"monsterinsights-inline-popular-posts-text\"><span class=\"monsterinsights-inline-popular-posts-label\" >Trending<\/span><div class=\"monsterinsights-inline-popular-posts-post\"><a class=\"monsterinsights-inline-popular-posts-title\"  href=\"https:\/\/www.pythonpool.com\/solved-runtimeerror-cuda-error-invalid-device-ordinal\/\">[Solved] runtimeerror: cuda error: invalid device ordinal<\/a><\/div><\/div><\/div><p><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-faqs-on-copy-list-in-python\"><span class=\"ez-toc-section\" id=\"FAQs_on_Copy_List_in_Python\"><\/span>FAQs on Copy List in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1648403370326\"><strong class=\"schema-faq-question\">What is a deep copy in Python?<\/strong> <p class=\"schema-faq-answer\">Deep copy in Python recursively copies the items found in the original list to the new object. This way, it creates a clone\/copy of the original list.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1648403541201\"><strong class=\"schema-faq-question\">What is a shallow copy in Python?<\/strong> <p class=\"schema-faq-answer\">In shallow copy, an object is created that then gets populated with the references of the items of the original list. One level of deep copying occurs in shallow copy.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1648403735591\"><strong class=\"schema-faq-question\">How can I create a deep copy of a list in Python?<\/strong> <p class=\"schema-faq-answer\">By using the copy module&#8217;s deepcopy method. For instance: <br\/><code>from copy import deepcopy<br\/>list1 = [[1,2,3],[4,5,6],[7,8,9]]<br\/>list2 = deepcopy(list1)<br\/>print(f\"list1:{list1}\\nlist2:{list2}\")<\/code><br\/><strong>list1:[[1, 2, 3], [4, 5, 6], [7, 8, 9]]<br\/>list2:[[1, 2, 3], [4, 5, 6], [7, 8, 9]]<\/strong><br\/><\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1648449539176\"><strong class=\"schema-faq-question\">Python copy generator to a list<\/strong> <p class=\"schema-faq-answer\">We can convert a generator to a list using the list method. For instance:<br\/><code>l = [[1,2,3],[4,5,6],[7,8,9]]<br\/>list l converted to a generator<br\/>gen_l = (elem for elem in l)<br\/>to convert generator to a list<br\/>gen_l_to_list = list(gen_l)<br\/>print(gen_l_to_list)<\/code><\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1648450496917\"><strong class=\"schema-faq-question\">Python copy queue to a list<\/strong> <p class=\"schema-faq-answer\">We can convert a queue to a list using the list method. For instance:<br\/><code>from collections import deque<br\/>que = deque()<br\/>que.append('tangiro')<br\/>que.append('nezko')<br\/>print(f\"que: {que}\\nType: {type(que)}\")<br\/>que_list = list(que)<br\/>print(f\"\\nque_list: {que}\\nType: {type(que_list)}\")<\/code><\/p> <\/div> <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>It is important to realize the distinction between shallow and deep copy. Accordingly, both have different use cases. We discussed different ways for copying a list in Python, for instance, using the list method, = operator, list comprehension, etc. I&nbsp;hope you have learned something new today.<\/p>\n\n\n<div class=\"monsterinsights-widget-popular-posts monsterinsights-widget-popular-posts-delta monsterinsights-popular-posts-styled monsterinsights-widget-popular-posts-columns-2\"><h2 class=\"monsterinsights-widget-popular-posts-widget-title\"><span class=\"ez-toc-section\" id=\"Trending_Python_Articles\"><\/span>Trending Python Articles<span class=\"ez-toc-section-end\"><\/span><\/h2><ul class=\"monsterinsights-widget-popular-posts-list\"><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-cant-compare-datetime-datetime-to-datetime-date\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/typeerror-cant-compare-datetime.datetime-to-datetime.date_.webp 1200w \" alt=\"[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] typeerror can&#8217;t compare datetime.datetime to datetime.date<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 11, 2024<\/span><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-nameerror-name-unicode-is-not-defined\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-nameerror-name-Unicode-is-not-defined.webp 1200w \" alt=\"[Fixed] nameerror: name Unicode is not defined\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] nameerror: name Unicode is not defined<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 2, 2024<\/span><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/solved-runtimeerror-cuda-error-invalid-device-ordinal\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Solved-runtimeerror-cuda-error-invalid-device-ordinal.webp 1200w \" alt=\"[Solved] runtimeerror: cuda error: invalid device ordinal\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Solved] runtimeerror: cuda error: invalid device ordinal<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 2, 2024<\/span><\/div><\/div><\/a><\/li><li ><a href=\"https:\/\/www.pythonpool.com\/fixed-typeerror-type-numpy-ndarray-doesnt-define-__round__-method\/\"><div class=\"monsterinsights-widget-popular-posts-image\"><img decoding=\"async\" src=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-300x157.webp\" srcset=\" https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-300x157.webp 300w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-1024x536.webp 1024w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method-768x402.webp 768w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2024\/01\/Fixed-typeerror-type-numpy.ndarray-doesnt-define-__round__-method.webp 1200w \" alt=\"[Fixed] typeerror: type numpy.ndarray doesn&#8217;t define __round__ method\" \/><\/div><div class=\"monsterinsights-widget-popular-posts-text\"><span class=\"monsterinsights-widget-popular-posts-title\" >[Fixed] typeerror: type numpy.ndarray doesn&#8217;t define __round__ method<\/span><div class=\"monsterinsights-widget-popular-posts-meta\" ><span class=\"monsterinsights-widget-popular-posts-author\">by Namrata Gulati<\/span><span>&#9679;<\/span><span class=\"monsterinsights-widget-popular-posts-date\">January 2, 2024<\/span><\/div><\/div><\/a><\/li><\/ul><\/div><p><\/p>","protected":false},"excerpt":{"rendered":"<p>There will be times when you might want to copy a list in Python. For instance, if you&#8217;re going to keep the original list untouched. &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Ways to Copy List in Python\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/#more-21734\" aria-label=\"More on Ways to Copy List in Python\">Read more<\/a><\/p>\n","protected":false},"author":29,"featured_media":22041,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[5090,5092,5087,5093,5086,5088],"class_list":["post-21734","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-copy-list-python","tag-deep-copy-list-python","tag-python-copy-list-to-new-list","tag-python-deep-copy-list","tag-python-list-copy","tag-python-make-copy-of-list","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Ways to Copy List in Python - Python Pool<\/title>\n<meta name=\"description\" content=\"In this article we will discuss how you can copy a list in python. We will go through various ways to achieve this.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/python-copy-list\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ways to Copy List in Python\" \/>\n<meta property=\"og:description\" content=\"There will be times when you might want to copy a list in Python. For instance, if you&#039;re going to keep the original list untouched. Instead, you may want\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python-copy-list\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-30T08:32:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-30T08:32:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/python-copy-list.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Nikhil Omkar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nikhil Omkar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/\"},\"author\":{\"name\":\"Nikhil Omkar\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/6faa89103f0ea990a146386f20d1454f\"},\"headline\":\"Ways to Copy List in Python\",\"datePublished\":\"2022-03-30T08:32:52+00:00\",\"dateModified\":\"2022-03-30T08:32:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/\"},\"wordCount\":740,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/python-copy-list.webp\",\"keywords\":[\"copy list python\",\"deep copy list python\",\"python copy list to new list\",\"python deep copy list\",\"python list copy\",\"python make copy of list\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/python-copy-list\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/\",\"url\":\"https:\/\/www.pythonpool.com\/python-copy-list\/\",\"name\":\"Ways to Copy List in Python - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/python-copy-list.webp\",\"datePublished\":\"2022-03-30T08:32:52+00:00\",\"dateModified\":\"2022-03-30T08:32:55+00:00\",\"description\":\"In this article we will discuss how you can copy a list in python. We will go through various ways to achieve this.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403370326\"},{\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403541201\"},{\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403735591\"},{\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648449539176\"},{\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648450496917\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/python-copy-list\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/python-copy-list.webp\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/python-copy-list.webp\",\"width\":1200,\"height\":628,\"caption\":\"python copy list\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ways to Copy List in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/6faa89103f0ea990a146386f20d1454f\",\"name\":\"Nikhil Omkar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/fe4e6cc08faea13ecb485e806625e9046dc70ffa984ada89243748e5353d3c13?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/fe4e6cc08faea13ecb485e806625e9046dc70ffa984ada89243748e5353d3c13?s=96&d=wavatar&r=g\",\"caption\":\"Nikhil Omkar\"}},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403370326\",\"position\":1,\"url\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403370326\",\"name\":\"What is a deep copy in Python?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Deep copy in Python recursively copies the items found in the original list to the new object. This way, it creates a clone\/copy of the original list.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403541201\",\"position\":2,\"url\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403541201\",\"name\":\"What is a shallow copy in Python?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"In shallow copy, an object is created that then gets populated with the references of the items of the original list. One level of deep copying occurs in shallow copy.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403735591\",\"position\":3,\"url\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403735591\",\"name\":\"How can I create a deep copy of a list in Python?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"By using the copy module's deepcopy method. For instance: <br\/>from copy import deepcopy<br\/>list1 = [[1,2,3],[4,5,6],[7,8,9]]<br\/>list2 = deepcopy(list1)<br\/>print(f\\\"list1:{list1}\\\\nlist2:{list2}\\\")<br\/><strong>list1:[[1, 2, 3], [4, 5, 6], [7, 8, 9]]<br\/>list2:[[1, 2, 3], [4, 5, 6], [7, 8, 9]]<\/strong><br\/>\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648449539176\",\"position\":4,\"url\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648449539176\",\"name\":\"Python copy generator to a list\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"We can convert a generator to a list using the list method. For instance:<br \/>l = [[1,2,3],[4,5,6],[7,8,9]]<br \/>list l converted to a generator<br \/>gen_l = (elem for elem in l)<br \/>to convert generator to a list<br \/>gen_l_to_list = list(gen_l)<br \/>print(gen_l_to_list)\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648450496917\",\"position\":5,\"url\":\"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648450496917\",\"name\":\"Python copy queue to a list\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"We can convert a queue to a list using the list method. For instance:<br \/>from collections import deque<br \/>que = deque()<br \/>que.append('tangiro')<br \/>que.append('nezko')<br \/>print(f\\\"que: {que}\\\\nType: {type(que)}\\\")<br \/>que_list = list(que)<br \/>print(f\\\"\\\\nque_list: {que}\\\\nType: {type(que_list)}\\\")\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Ways to Copy List in Python - Python Pool","description":"In this article we will discuss how you can copy a list in python. We will go through various ways to achieve this.","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:\/\/www.pythonpool.com\/python-copy-list\/","og_locale":"en_US","og_type":"article","og_title":"Ways to Copy List in Python","og_description":"There will be times when you might want to copy a list in Python. For instance, if you're going to keep the original list untouched. Instead, you may want","og_url":"https:\/\/www.pythonpool.com\/python-copy-list\/","og_site_name":"Python Pool","article_published_time":"2022-03-30T08:32:52+00:00","article_modified_time":"2022-03-30T08:32:55+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/python-copy-list.webp","type":"image\/webp"}],"author":"Nikhil Omkar","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Nikhil Omkar","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/python-copy-list\/"},"author":{"name":"Nikhil Omkar","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/6faa89103f0ea990a146386f20d1454f"},"headline":"Ways to Copy List in Python","datePublished":"2022-03-30T08:32:52+00:00","dateModified":"2022-03-30T08:32:55+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-copy-list\/"},"wordCount":740,"commentCount":0,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/python-copy-list.webp","keywords":["copy list python","deep copy list python","python copy list to new list","python deep copy list","python list copy","python make copy of list"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/python-copy-list\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/www.pythonpool.com\/python-copy-list\/","url":"https:\/\/www.pythonpool.com\/python-copy-list\/","name":"Ways to Copy List in Python - Python Pool","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/python-copy-list.webp","datePublished":"2022-03-30T08:32:52+00:00","dateModified":"2022-03-30T08:32:55+00:00","description":"In this article we will discuss how you can copy a list in python. We will go through various ways to achieve this.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403370326"},{"@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403541201"},{"@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403735591"},{"@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648449539176"},{"@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648450496917"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/python-copy-list\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/python-copy-list.webp","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2022\/03\/python-copy-list.webp","width":1200,"height":628,"caption":"python copy list"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"Ways to Copy List in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/6faa89103f0ea990a146386f20d1454f","name":"Nikhil Omkar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/fe4e6cc08faea13ecb485e806625e9046dc70ffa984ada89243748e5353d3c13?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fe4e6cc08faea13ecb485e806625e9046dc70ffa984ada89243748e5353d3c13?s=96&d=wavatar&r=g","caption":"Nikhil Omkar"}},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403370326","position":1,"url":"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403370326","name":"What is a deep copy in Python?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Deep copy in Python recursively copies the items found in the original list to the new object. This way, it creates a clone\/copy of the original list.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403541201","position":2,"url":"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403541201","name":"What is a shallow copy in Python?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"In shallow copy, an object is created that then gets populated with the references of the items of the original list. One level of deep copying occurs in shallow copy.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403735591","position":3,"url":"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648403735591","name":"How can I create a deep copy of a list in Python?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"By using the copy module's deepcopy method. For instance: <br\/>from copy import deepcopy<br\/>list1 = [[1,2,3],[4,5,6],[7,8,9]]<br\/>list2 = deepcopy(list1)<br\/>print(f\"list1:{list1}\\nlist2:{list2}\")<br\/><strong>list1:[[1, 2, 3], [4, 5, 6], [7, 8, 9]]<br\/>list2:[[1, 2, 3], [4, 5, 6], [7, 8, 9]]<\/strong><br\/>","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648449539176","position":4,"url":"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648449539176","name":"Python copy generator to a list","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"We can convert a generator to a list using the list method. For instance:<br \/>l = [[1,2,3],[4,5,6],[7,8,9]]<br \/>list l converted to a generator<br \/>gen_l = (elem for elem in l)<br \/>to convert generator to a list<br \/>gen_l_to_list = list(gen_l)<br \/>print(gen_l_to_list)","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648450496917","position":5,"url":"https:\/\/www.pythonpool.com\/python-copy-list\/#faq-question-1648450496917","name":"Python copy queue to a list","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"We can convert a queue to a list using the list method. For instance:<br \/>from collections import deque<br \/>que = deque()<br \/>que.append('tangiro')<br \/>que.append('nezko')<br \/>print(f\"que: {que}\\nType: {type(que)}\")<br \/>que_list = list(que)<br \/>print(f\"\\nque_list: {que}\\nType: {type(que_list)}\")","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/21734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=21734"}],"version-history":[{"count":59,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/21734\/revisions"}],"predecessor-version":[{"id":22052,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/21734\/revisions\/22052"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/22041"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=21734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=21734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=21734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}