#๐Ÿ”’ Sorting function

17 messages ยท Page 1 of 1 (latest)

dry dune
#

I have a list such as https://codeshare.io/5vPxB7

For this list I need to apply sort method and verify the above and list and sorted list is same. I am getting error in organization starting with H. Can you please suggest a sorting method in python that returns the above list?
These are bunch of faker names.
Thanks!!!!!

dusk pastureBOT
#

@dry dune

Python help channel opened

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.

alpine lichen
#

!d sorted

dusk pastureBOT
#

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)...
alpine lichen
#

!d list.sort

dusk pastureBOT
#

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.
dry dune
#

Did not work it's misplacing few of the words

#

Tried with both sorted and sort

alpine lichen
#

I guess it's the sorting criterion that is different from what you expect

#

like "," being before "-" but you would expect the opposite

dry dune
#

Sorry for the dumb question
Are u referring to the unicode value
And can we implement that kind of sorting??

alpine lichen
alpine lichen
dry dune
#

Alright thanks for the help!! Let me check again what I can do
Thanks!

quick grove
#

do you want do sort it in alphabetical order?

dusk pastureBOT
#
Python help channel closed for inactivity

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.