Tag: clone

  • How to Clone a List in Python: Understanding the Basics

    Python, being a versatile and powerful programming language, offers a multitude of ways to manipulate and work with lists. Lists are one of the most commonly used data structures in Python, providing a flexible way to store and manipulate collections of items. When working with lists, you may come across a scenario where you need to create a copy or clone of an existing list. In this article, we will explore various methods to clone a list in Python.

    Before we dive into the different approaches, it’s important to understand the distinction between a shallow copy and a deep copy. In Python, a shallow copy creates a new list object, but the elements within the list are still references to the original objects. On the other hand, a deep copy creates a completely independent copy of the list and its elements, ensuring that changes made to one list do not affect the other. Depending on your requirements, you can choose the appropriate method accordingly.
    (more…)

  • JavaScript Fetch API Explained By Examples

    The JavaScript Fetch API helps users create asynchronous HTTP requests. Fetch API is an easy and intuitive method for sending HTTP requests in a web browser where the content type is typically application json. For a web-application whose XMLHttpRequest (XHR) object is available for downloading, fetch will perform any task as XHR objects will. The fetch API is further simplified and easier to use. Using the Promise system gives more flexibility to the request using to servers by the internet browser. This fetch() function has a global scope which instructs the browser to redirect a request to the web.

    (more…)

  • Deep clone an object with C#

    Cloning is a common thing I need to do in my C# project. The most common case I use this is with my Entity Framework projects. I first fetch my object using a standard Linq query.

    Once I have this object, EF is now tracking any changes to the object. I want a duplicate object of this so I can track a before and after state, so I want to clone the fetched object. To do this I use JSON.Net nuget package.

    (more…)

  • Deep clone an object with JavaScript

    To copy/clone an object using JavaScript, you will want to leverage the JSON.parse function in combination with the JSON.stringify function.

    (more…)

  • Deep clone an object with jQuery

    To copy/clone an object using jQuery, you will want to leverage the extend function. This function accepts N objects to clone/merge as well as a boolean to indicate whether it should copy recursively or not.

    (more…)