{"type":"rich","version":"1.0","provider_name":"Transistor","provider_url":"https://transistor.fm","author_name":"Data Science Tech Brief By HackerNoon","title":"How Shallow and Deep Copies Work in Python","html":"<iframe width=\"100%\" height=\"180\" frameborder=\"no\" scrolling=\"no\" seamless src=\"https://share.transistor.fm/e/8160020c\"></iframe>","width":"100%","height":180,"duration":511,"description":"\n        This story was originally published on HackerNoon at: https://hackernoon.com/how-shallow-and-deep-copies-work-in-python.\nI copied a Python dictionary, but the original still changed. Here's how shallow copies, shared references, and deep copies actually work.\nCheck more stories related to data-science at: https://hackernoon.com/c/data-science.\n            You can also check exclusive content about #python-programming, #python-dictionaries, #shallow-copy, #deep-copy, #python-mutability, #object-references, #python-debugging, #mutable-default-arguments,  and more.\nThis story was written by: @sohelalam79. Learn more about this writer by checking @sohelalam79's about page,\n            and for more stories, please visit hackernoon.com.\n`dict.copy()` only copies the outer dictionary nested lists/dicts stay shared, so mutating them changes both copies. It's not a bug, it's shallow copy working as designed. Use `deepcopy()` only when you need full independence.","thumbnail_url":"https://img.transistorcdn.com/8VxAgS1Ll3FJEERcAdhFdqqXJMnE7OfD2RUvrjauLt0/rs:fill:0:0:1/w:400/h:400/q:60/mb:500000/aHR0cHM6Ly9pbWct/dXBsb2FkLXByb2R1/Y3Rpb24udHJhbnNp/c3Rvci5mbS9zaG93/LzQxMjY4LzE2ODM1/ODI1ODUtYXJ0d29y/ay5qcGc.webp","thumbnail_width":300,"thumbnail_height":300}