[Tutor] Help with putting numbers from highest to lowest.

Roel Schroeven roel at roelschroeven.net
Wed Sep 27 16:33:32 EDT 2017


edmundo pierre via Tutor schreef op 27/09/2017 15:10:
> Hello,
> When I used sort() to do that, but my problem is that sort() just arrange numbers from small to big, not from big to small. That is the issue I am having now. For instance:
> # The user is entering those numbers:a = 2.7b = 4.7c= 5.8d = 7.9# I will like the answer to be like this: 7.9  5.8  4.7 2.7
> #but if I use sort(), I will have that answer, but I do not want that:2.7 4.7 5.8 7.9

You can reverse the sort order with reverse=True, like so:

numbers = [7.9, 4.7, 2.7, 5.8]
numbers.sort(reverse=True)
print(numbers)

--> [7.9, 5.8, 4.7, 2.7]

See https://docs.python.org/3/library/stdtypes.html?highlight=sort#list.sort

-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
   -- Isaac Asimov

Roel Schroeven



More information about the Tutor mailing list