To sort an array in Python, you can use the built-in sorted()
function. The sorted()
function takes an iterable as an argument, and returns a new sorted list in ascending order.
Here's an example of how to use sorted()
to sort an array:
main.py65 chars4 lines
Output:
main.py16 chars2 lines
Alternatively, you can use the sort()
method of a list to sort it in place:
main.py44 chars4 lines
Output:
main.py16 chars2 lines
gistlibby LogSnag