This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: List.sort ERROR
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: meng_xiaohui, steven.daprano
Priority: normal Keywords:

Created on 2021-09-13 02:02 by meng_xiaohui, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg401679 - (view) Author: (meng_xiaohui) Date: 2021-09-13 02:02
There is a bug in this method:

L.sort(key=None, reverse=False) -> None
L is an instance of list.

Argument key is a function. If L is in the body of argument key, L is always an empty list in test case, which is wrong

=================
Run this:

F = ['2', '3', '1']
G = ['7', '9', '8']

def key(i):
    print(F)
    print(G)
    res = int(i) + len(F) + len(G)
    return res

G.sort(key=key)
F.sort(key=key)

=================
Actual output:
['2', '3', '1']
[]
['2', '3', '1']
[]
['2', '3', '1']
[]
[]
['7', '8', '9']
[]
['7', '8', '9']
[]
['7', '8', '9']
msg401680 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-09-13 02:10
Sorry, it is not clear what you think is the bug. What output do you expect?

When I run the code, F and G are correctly sorted.
msg401681 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-09-13 02:15
Wait, are you talking about the list appearing to be empty during the sort? That's expected behaviour and not a bug:

https://docs.python.org/3/library/stdtypes.html#list.sort

I'm going to close this issue as Not A Bug. If the problem is something else, please re-open it with:

- an explanation of what you think the bug is;

- why you think it is a bug;

- a simple test case;

- the output you expect;

- and the actual output.


It is not enough to give the actual output with no explanation for why you think it is wrong.
History
Date User Action Args
2022-04-11 14:59:49adminsetgithub: 89342
2021-09-13 02:15:41steven.dapranosetstatus: open -> closed
resolution: not a bug
messages: + msg401681

stage: resolved
2021-09-13 02:10:19steven.dapranosetnosy: + steven.daprano
messages: + msg401680
2021-09-13 02:02:42meng_xiaohuicreate