#๐ Sorting function
17 messages ยท Page 1 of 1 (latest)
@dry dune
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
!d sorted
sorted(iterable, /, *, key=None, reverse=False)```
Return a new sorted list from the items in *iterable*.
Has two optional arguments which must be specified as keyword arguments.
*key* specifies a function of one argument that is used to extract a comparison key from each element in *iterable* (for example, `key=str.lower`). The default value is `None` (compare the elements directly)...
!d list.sort
sort(*, key=None, reverse=False)```
This method sorts the list in place, using only `<` comparisons between items. Exceptions are not suppressed - if any comparison operations fail, the entire sort operation will fail (and the list will likely be left in a partially modified state).
[`sort()`](https://docs.python.org/3/library/stdtypes.html#list.sort) accepts two arguments that can only be passed by keyword ([keyword-only arguments](https://docs.python.org/3/glossary.html#keyword-only-parameter)):
*key* specifies a function of one argument that is used to extract a comparison key from each list element (for example, `key=str.lower`). The key corresponding to each item in the list is calculated once and then used for the entire sorting process. The default value of `None` means that list items are sorted directly without calculating a separate key value.
I guess it's the sorting criterion that is different from what you expect
like "," being before "-" but you would expect the opposite
Sorry for the dumb question
Are u referring to the unicode value
And can we implement that kind of sorting??
Idk what is use to sort characters, maybe unicode value, maybe something else
idk how to implement it tho
Alright thanks for the help!! Let me check again what I can do
Thanks!
do you want do sort it in alphabetical order?
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.