Python Forum
Sorting a copied list is also sorting the original list ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sorting a copied list is also sorting the original list ?
#3
C1=[7,3,6,5,4,2,1]
C2=C1
This is just making C2 also point at the same object as C1

To make a new copy of the list use
c2 = c1[:]
or
c2 = list(c1)
Reply


Messages In This Thread
RE: Sort list - by ichabod801 - Apr-11-2019, 05:03 PM
RE: Sort list - by Yoriz - Apr-11-2019, 05:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Up Sorting Steps MoreMoney 19 870 Mar-31-2024, 10:59 AM
Last Post: Pedroski55
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,188 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  Variable sorting methods for Enum DataClasses koen 1 779 May-30-2023, 07:31 PM
Last Post: deanhystad
  Delete strings from a list to create a new only number list Dvdscot 8 1,557 May-01-2023, 09:06 PM
Last Post: deanhystad
  Need help with sorting lists as a beginner Realist1c 1 757 Apr-25-2023, 04:32 AM
Last Post: deanhystad
  List all possibilities of a nested-list by flattened lists sparkt 1 929 Feb-23-2023, 02:21 PM
Last Post: sparkt
  Check DataFrames with different sorting in columns and rows Foxyskippy 0 782 Nov-19-2022, 07:49 AM
Last Post: Foxyskippy
  Сheck if an element from a list is in another list that contains a namedtuple elnk 8 1,861 Oct-26-2022, 04:03 PM
Last Post: deanhystad
  List Sorting Problem ZZTurn 5 1,351 Sep-22-2022, 11:23 PM
Last Post: ZZTurn
  Sorting a dictionary v_mn 2 906 Sep-12-2022, 06:50 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020