HomeToolsAbout

Sort

String Sorting

String Sorting using sorted:

s = "python" sorted_string = ''.join(sorted(s))

Returns ASCII based result for string.

If you are sorting a mixed case string, use key=str.lower as second parameter:

a = "Hello World!" "".join(sorted(a,key=str.lower))

Number Sorting

numbers = [6, 9, 3, 1] sorted(numbers) # [1, 3, 6, 9] # original array preserved numbers # [6, 9, 3, 1]
AboutContact