Light Mode
Dark Mode
sorted reverse

Hi,

Given the following example:

print ("Sorted")
print(sorted([2.2, 5.6, 5.9], key=int))
print ("Sorted reverse")
print(sorted([2.2, 5.6, 5.9], key=int, reverse=True))

It gives the following output:

>>> print ("Sorted")
Sorted
>>> print(sorted([2.2, 5.6, 5.9], key=int))
[2.2, 5.6, 5.9]
>>> print ("Sorted reverse")
Sorted reverse
>>> print(sorted([2.2, 5.6, 5.9], key=int, reverse=True))
[5.6, 5.9, 2.2]
>>>

Given the first print, i would be able to return max as:

sorted([2.2, 5.6, 5.9], key=int)[-1]

but i returns a different value than

sorted([2.2, 5.6, 5.9], key=int, reverse=True)[0]

Is this purely the order of the list ?

Created: Nov. 8, 2017, 10:16 a.m.
Updated: Nov. 8, 2017, 9:31 p.m.
0
8
User avatar
rekkebus