Python List Sorting with sorted() and sort()
In this article, we’ll examine multiple ways to sort lists in Python. Python ships with two built-in methods for sorting lists and other iterable objects. The method chosen for a particular use-case often depends on whether we want to sort a list in-place or return a new version of the sorted list. Assuming we want to sort a list in place, we can use the list.sort() method as follows: >>> pets = [‘Turtle’, ‘Cat’, ‘Fish’, ‘Dingo’] >>> pets.sort() >>> pets […]
Read more