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

    4147 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 …

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

    Feb 13, 2014 · It will only copy references that are held by the list. If an element in the list holds a reference to another object, that won't be copied. 9 times out of 10 you just need the shallow …

  3. Copying nested lists in Python - Stack Overflow

    Then you create a copy of a: b = a.copy. This is a different list, but it contains the same 'sub-lists' this means that changing b, for example b.append([5, 6]) will not change a, however changing …

  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 …

  5. Python copy a list of lists - Stack Overflow

    Feb 24, 2015 · When you call regular copy.copy() you are performing a shallow copy. This means that in a case of a list-of-lists, you will get a new copy of the outer list, but it will contain the …

  6. copy a list in python - Stack Overflow

    Jul 13, 2013 · 0 As an additional data point, Python 3.3 added the copy method as a readable alternative to the slicing syntax. So white.copy() also creates a shallow copy of the list white

  7. python - How to make a copy of a list of objects not change when ...

    Jul 9, 2011 · Possible Duplicates: How to clone a list in python? What is the best way to copy a list in Python?

  8. Slicing a list in Python without generating a copy

    Aug 9, 2024 · Given a list of integers L, I need to generate all of the sublists L[k:] for k in [0, len(L) - 1], without generating copies. How do I accomplish this in Python? With a buffer object …

  9. Best way to create a "reversed" list in Python? - Stack Overflow

    In Python, what is the best way to create a new list whose items are the same as those of some other list, but in reverse order? (I don't want to modify the existing list in place.) Here is one so...

  10. Copy multiple files in Python - Stack Overflow

    Aug 3, 2010 · How to copy all the files present in one directory to another directory using Python. I have the source path and the destination path as string.