Return and print review, flights example

We worked on two extended examples, as described below.

A mystery function

We first worked on this function:

def mystery(lst: list) -> bool:
    """a mysterious function"""
    found = false
    for x in lst:
        if x > 2:
            found = true
    return found

See the lecture capture for details. We talked about:

  • What the function does
  • How it could be re-written while preserving its behavior
  • The distinction between “print” and “return”
  • Accumulators and for-loops

Flights

We then worked on an example of data structure design. Let’s say we are running an airline. Our flights have numbers that correspond to arrival airport, departure airport, and time of day. Each flight runs on many days, and we want to track passenger lists. How might we store this information so that we can access flights by date and by number?

We talked about several different options:

  • A hashtable where the keys are dates and the values are lists of flights with numbers
  • A hashtable where the keys are flight numbers and the values are lists of flights with dates
  • A nested hashtable, where the keys are flight numbers and the values are themselves hashtables from dates to flight information
  • A nested hashtable where the “outer” keys are dates and the “inner” keys are flight numbers

See the lecture capture for more information.