differentmatt / filbert

JavaScript parser of Python
Other
133 stars 27 forks source link

sorted function sorts by comparison and not key function #43

Closed bhargavvader closed 10 years ago

bhargavvader commented 10 years ago

The functionality was changed in Python3. https://docs.python.org/3/library/stdtypes.html#list.sort https://docs.python.org/3/library/functools.html#functools.cmp_to_key

def foo(x):
    return -x

sorted([100, 1, 0, 22, 33, 5, 55], key=foo)

should sort the array in descending order but the output is different

Expected output: [ 100, 55, 33, 22, 5, 1, 0 ]
Actual output: [ 100, 1, 0, 22, 33, 5, 55 ]
differentmatt commented 10 years ago

I think this is a dupe of #38, but please reopen if that is incorrect.