Below is my code I have printing this in ascending order I now need to print it in descending order but don't know how?
list = [37,-59,4,0,15,-12,9,0]
If you need the list both in ascending and descending order, you can get your list in reverse like so:
sorted_list_oldskool[::-1]
If you only need it in descending order, AMACB's answer is probably the most efficient.
If, for whatever reason you want to take your existing sorting logic and have it produce a list in descending order, you should change
if unsorted_list[i] <= sorted_list_oldskool[j]:
to
if unsorted_list[i] >= sorted_list_oldskool[j]:
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments