From the course: Python Standard Library Essential Training (2019)
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Using the sorted() function - Python Tutorial
From the course: Python Standard Library Essential Training (2019)
Using the sorted() function
- [Instructor] One of the primary uses for Python these days is for processing data. In this chapter, we're going to look at some of the ways that the Python standard library provides for manipulating and working with different types of data. So let's start with something simple, such as sorting a set of data. So here in the editor, I'm going to open up sorting_start, and there's already a list of sample test scores in a random order, and we want to sort them. So Python's built-in function for sorting data is called sorted, and we can use that here to perform this operation. So I'll write sortedScores is equal to, and then I'll call the sorted function on testScores. Then we'll print out the result. So let's go ahead and run that. And we can see here in the output that the data has now been sorted from lowest to highest. Now of course, we might want to sort the data in descending order, which we can specify when we call the function. So let's modify our function call to do exactly…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.