in python I encountered error during using sort function
python, sorting
Solution
`list.sort` sorts in-place, and `g = d` assigns the reference to the list without copying it. Copy the list as `g = d[:]` before sorting, or use the built-in function `sorted` instead:
g = sorted(d)
Problem
I have encountered a problem while using sort function of python. ``` >>>d = [23,45,67,5,4,23,45,89] >>>d[5] 23 >>>g = d >>>g.sort() >>>d[5] 45 ``` Is there any way, i can get g sorted without disturbing d.