Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug report
The sorted() function is returning the wrong result for a specific input when using the key parameter. Here's my test case:
sorted()
def test(input: list, expected: list): indices = sorted(range(len(input)), key=input.__getitem__) print(f'{indices == expected}, indices={indices}, expected={expected}') test([1,2,3,4,5,6], [0,1,2,3,4,5]) # Output: True, indices=[0, 1, 2, 3, 4, 5], expected=[0, 1, 2, 3, 4, 5] test([1,2,3,4,6,5], [0,1,2,3,5,4]) # Output: True, indices=[0, 1, 2, 3, 5, 4], expected=[0, 1, 2, 3, 5, 4] test([1,2,3,6,5,4], [0,1,2,5,4,3]) # Output: True, indices=[0, 1, 2, 5, 4, 3], expected=[0, 1, 2, 5, 4, 3] test([3,2,1,5,6,4], [2,1,0,4,5,3]) # Output: False, indices=[2, 1, 0, 5, 3, 4], expected=[2, 1, 0, 4, 5, 3]
The 4th (last) test prints False because it is not sorting the input correctly. Looks like a bug, or I'm missing something here.
False
Your environment
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Bug report
The
sorted()function is returning the wrong result for a specific input when using the key parameter. Here's my test case:The 4th (last) test prints
Falsebecause it is not sorting the input correctly. Looks like a bug, or I'm missing something here.Your environment
The text was updated successfully, but these errors were encountered: