I sorted my list using seq.sort(key = lambda x: x[1]) into [[4, 0], [8, 0], [1, 0], [10, 0], [2, 2], [0, 2], [3, 3], [6, 3], [7, 3], [9, 3], [5, 4]], but i want it reversed like this [[5, 4], [9, 3], [7, 3], [6, 3], [3, 3], [0 , 2], [2 ,2], [10, 0], [1, 0], [8, 0], [4, 0]]. I've tried doing this seq = seq[::-1] , but doesn't work. It works if i store it in a new list new_list = seq[::-1], but i want to use the same list seq.
            Asked
            
        
        
            Active
            
        
            Viewed 96 times
        
    -2
            
            
        
        Ruben Gavris
        
- 5
 - 3
 
- 
                    1`seq = seq[::-1]` should work. – xjcl Mar 31 '21 at 20:40
 - 
                    What do you mean new list? I believe with seq[::-1] you are only getting a new reference, not a deep copy of the existing list. – Anthony O Mar 31 '21 at 20:41
 - 
                    Does this answer your question? [Python list sort in descending order](https://stackoverflow.com/questions/4183506/python-list-sort-in-descending-order) `list.sort()` takes a boolean `reverse` argument – Pranav Hosangadi Mar 31 '21 at 20:42
 - 
                    Seems you’re trying to reverse the list not sort it – Jab Mar 31 '21 at 20:43
 
1 Answers
0
            Look at this link
You were on a good path with the sort() function, but the sort function just has an extra 'reverse' parameter which is False by default. Your code should be seq.sort(key = lambda x: x[1], reverse=True)
        Xander
        
- 418
 - 2
 - 12
 
- 
                    1Weird...I tried that but, didn't work earlier. Now it works! Thanks! It maybe was the online editor i was using. – Ruben Gavris Mar 31 '21 at 20:54