In Python, which of the following functions should we use to sort a list/array…
2024
In Python, which of the following functions should we use to sort a list/array in natural order?
- A.
natcasesort()
- B.
casesort()
- C.
naturalsort()
- D.
More than one of the above
- E.
None of the above
Attempted by 1373 students.
Show answer & explanation
Correct answer: E
A) natcasesort(): Incorrect. It is a PHP function, not a Python function.
B) casesort(): Incorrect. It is not a valid Python sorting function.
C) naturalsort(): Incorrect. Python has no built-in naturalsort() function. Natural sorting is possible with a custom key or an external library such as natsort, whose common function is natsorted().
D) More than one of the above: Incorrect, because none of the listed function names is valid in Python.
E) None of the above: Correct.