Overview

This module covers two important tools Python gives us for dealing with collections of data: sorting and comprehensions/generator expressions. It also covers some important background information.

Learning Objectives

After completing this module, you should understand

  • How Python compares numbers, booleans, and sequence data types (including strings)

  • How to use the sort() method of lists and the sorted() built-in function, and the differences between them

  • How to sort in descending order

  • How to modify sort criteria using a key function

  • How to write a key function

  • How to write a lambda expression

  • How to sort values using multiple criteria

  • How to use the min() and max() functions

  • How to write a list comprehension

  • How to filter data with a list comprehension

  • How to write a generator expression and how it differs from a list comprehension

  • How to write a set comprehension

  • How to write a dictionary comprehension

Readings

You may find it helpful to refer to the following resources: