How to sort a list in reverse order Python

2 Answers

0 votes
lst = ['c', 'b', 'a', 'B', 'g', 'b', 'e', 'A'];
 
print(lst)
 
lst.sort(reverse=True)
 
print(lst)
 
 
 
     
'''
run:
     
['c', 'b', 'a', 'B', 'g', 'b', 'e', 'A']
['g', 'e', 'c', 'b', 'b', 'a', 'B', 'A']
 
'''

 



answered Jun 24, 2020 by avibootz
0 votes
lst = ['c', 'b', 'a', 'B', 'g', 'b', 'e', 'A'];
 
print(lst)
 
lst = sorted(lst, key=str.lower, reverse=True)
 
print(lst)
 
 
 
     
'''
run:
     
['c', 'b', 'a', 'B', 'g', 'b', 'e', 'A']
['g', 'e', 'c', 'b', 'B', 'b', 'a', 'A']
 
'''

 



answered Jun 24, 2020 by avibootz

Related questions

...