From the course: Python Functions for Data Science
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Python sorted() function - Python Tutorial
From the course: Python Functions for Data Science
Python sorted() function
- A powerful built in Python function that is fundamental when working with sequences of data is the function sorted. Sorted takes in a sequence as the required input and can also take in a keyword argument named reverse as an optional input. Now reverse can be set to either True or False. If reverse is not specified in the function call, reverse is set to false by default and ascending order is used to sort. On the other hand, if reverse is set to True in the function call, descending order is used to sort. Sorted returns a new sorted list from the items in the given sequence and does not modify the given sequence itself. To illustrate how the function sorted works I'll be walking through some examples. First, let's say that I have a variable named names containing a list of the names of some people as strings. To sort the names in this list in ascending alphabetical order and save the sorted version in a new variable,…
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.
Contents
-
-
-
Python print() function2m 30s
-
(Locked)
Python input() function2m 1s
-
(Locked)
Python abs() function1m 57s
-
(Locked)
Python round() function2m 10s
-
(Locked)
Python min() function1m 42s
-
(Locked)
Python max() function1m 41s
-
(Locked)
Python sorted() function3m 39s
-
(Locked)
Python sum() function1m 1s
-
(Locked)
Python len() function2m 28s
-
(Locked)
Python type() function2m 22s
-
-
-
-
-
-
-
-