0

Python Version used: Python 3.11.3

Code :

original_list= [4, 2, 0, 3, 1]

duplicate_list=original_list
duplicate_list.sort()

print(original_list) 

Output :

[0, 1, 2, 3, 4]

When I sort the duplicate_list using the sort() method, why the original_list is also getting sorted ?

I was expecting that the original list should not be affected.

Also when I use the sorted() function the original_list does NOT gets affected.

0 Answers0