First page Back Continue Last page Overview Graphics

sort

Python lists have a built-in sort() method that modifies the list in-place and a sorted() built-in function that builds a new sorted list from an iterable.

>>> lst = [123,17,4,69,9,259,99]

>>> sorted(lst)

[4, 9, 17, 69, 99, 123, 259]

>>> lst

[123, 17, 4, 69, 9, 259, 99]

>>> lst.sort()

>>> lst

[4, 9, 17, 69, 99, 123, 259]

>>>