First page Back Continue Last page Overview Graphics

Defining an Ordering

Task: Sort a list of numbers as strings (alphabetically)

>>> lst = [23, 2, 4, 12, 1, 123, 243, 3, 33]

>>>

>>> lst.sort(key=str)

>>> print(lst)

The result:

>>> [1, 12, 123, 2, 23, 243, 3, 33, 4]