About 12,000,000 results
Open links in new tab
  1. python - How do I clone a list so that it doesn't change unexpectedly ...

    4149 new_list = my_list doesn't actually create a second list. The assignment just copies the reference to the list, not the actual list, so both new_list and my_list refer to the same list after the assignment. …

  2. python - What is the difference between shallow copy, deepcopy and ...

    May 6, 2017 · Below code demonstrates the difference between assignment, shallow copy using the copy method, shallow copy using the (slice) [:] and the deepcopy. Below example uses nested lists …

  3. How can I create a copy of an object in Python? - Stack Overflow

    Jan 25, 2011 · To get a fully independent copy of an object you can use the copy.deepcopy() function. For more details about shallow and deep copying please refer to the other answers to this question …

  4. python - How to deep copy a list? - Stack Overflow

    copy() is a shallow copy function. If the given argument is a compound data structure, for instance a list, then Python will create another object of the same type (in this case, a new list) but for everything …

  5. Copying and pasting code directly into the Python interpreter

    My answer is specifically about copy-pasting into the standard python shell (only tested on linux). Depending on where the code comes from and how it is originally formatted the whitespace may or …

  6. python - How to copy a dictionary and only edit the copy - Stack …

    Mar 18, 2010 · A shallow copy constructs a new compound object and then (to the extent possible) inserts references into it to the objects found in the original. A deep copy constructs a new compound …

  7. Deep copy of a dict in python - Stack Overflow

    Feb 24, 2011 · 653 I would like to make a deep copy of a dict in python. Unfortunately the .deepcopy() method doesn't exist for the dict. How do I do that?

  8. python - What is the best way to copy a list? - Stack Overflow

    Feb 13, 2014 · So, is the only way to get a deepcopy of a list by using the copy module? Seems strange that Python doesn't include deep copy in its standard functionality.

  9. python - why should I make a copy of a data frame in pandas - Stack ...

    Dec 28, 2014 · When selecting a sub dataframe from a parent dataframe, I noticed that some programmers make a copy of the data frame using the .copy() method. For example, X = …

  10. python - How do I copy a file? - Stack Overflow

    How do I copy a file in Python?copy2(src,dst) is often more useful than copyfile(src,dst) because: it allows dst to be a directory (instead of the complete target filename), in which case the basename of …