New issue
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
Improve documentation of list.sort and sorted() #51506
Comments
On my Python 3.1, help() for sorted returns sort(...)
L.sort(key=None, reverse=False) -- stable sort *IN PLACE*
sorted(...)
sorted(iterable, key=None, reverse=False) --> new sorted list Kindly suggest this be expanded. Here's some text: sort(...) Sorts the sequence with a fast stable sort. The sequence is modified in a = [1, 3, 2]
a.sort()
# a is now [1, 2, 3] Use the "sorted()" built-in function if you need to preserve the Set "reverse" to True to sort the elements in reverse order. A function a = [{'k': 'foo'}, {'k': 'bar'}]
a.sort(key=lambda x: x['k'])
# a is now [{'k': 'bar'}, {'k': 'foo'}] Note that "key" can be used to solve many sorting problems, e.g. The sort is stable which means that the relative order of elements that sorted(...) Sorts the sequence with a fast stable sort and returns a new list with [same text as before] I'm not sure how this interacts with what's in the online help |
Raymond, do you have an opinion on this? |
I'm inclined to leave the on-line help docstring as-is (pretty much Instead, was thinking of updating the sorting how-to and providing a |
If you think it's too long, here's a shorter version: Sorts sequence in place with a fast stable sort, returning None. key is a = [1, 3, 2]
a.sort() # a is now [1, 2, 3] Use the "sorted()" built-in function if you need to preserve the Is this better? You could whack the last comment about sorted and/or the |
Will look at it and make an update, but not right away. |
OK, thanks! :) Sorry about the unintended nosy list removal, my browser |
After more thought, am leaving the doc strings as-is. They are succinct and accurate. I have updated the sorting how-to to more thoroughly cover the basics of sorting. |
Okay. I can only say that while the current docstrings are likely good reminders for you, knowing Python in and out, they were pretty useless to me as documentation, which I believe docstrings should be, they're called docstrings, after all, not reminderstrings. :) I fail to see how including more info can hurt in any way, you're not forced to read it if you don't need it, so I hope you (or somebody else) will reconsider at some point. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: