May 2019
Beginner
528 pages
29h 51m
English
A common computing task called sorting enables you to arrange data either in ascending or descending order. Sorting is an intriguing problem that has attracted intense computer-science research efforts. It’s studied in detail in data-structures and algorithms courses. We discuss sorting in more detail in the “Computer Science Thinking: Recursion, Searching, Sorting and Big O” chapter.
List method sort modifies a list to arrange its elements in ascending order:
In [1]: numbers = [10, 3, 7, 1, 9, 4, 2, 8, 5, 6]In [2]: numbers.sort()In [3]: numbersOut[3]: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
To sort a list in descending order, call list method sort with the ...
Read now
Unlock full access