Lecture notes · Programming in Python · Lecture 9

Lambda Functions, Tuples, and Lists

MIT 6.100L Intro to CS and Programming using Python, lecture 9, explained in plain English

Want this lecture to stick? In LessonBound you get checked practice questions for every part, can ask about anything you don't get, and can listen with your screen off. Free, no ads.

Learn this lecture free

Watch or read the original lecture: MIT OpenCourseWare.

Part 1 · 0:00–10:00

This part explains lambda functions, which are short, nameless functions you can write in one line when you only need one.

Key ideas

Words to know

anonymous function
A function that has no name. You create it and use it in the same place.
lambda
The keyword that tells Python you are writing a short, nameless function in one line.
parameter
An input name listed in a function's definition, which receives a value when the function is called.
environment
The space Python makes for each function call, which keeps track of the names and values used during that call.

Example

Think of a lambda like a sticky note with a quick instruction written on it, such as 'add 2 to whatever number you get.' You use the note once, right where you need it, and then throw it away. A named function is more like a recipe card in a binder, which you keep so you can use it again and again.

3 checked practice questions for this part are in the app.

Part 2 · 10:00–20:00

This part traces how a function that takes another function works step by step, then introduces tuples, a new kind of container that holds an ordered list of items.

Key ideas

Words to know

formal parameter
A name listed in a function's definition that stands in for a value. For example, n in do_twice.
scope
A private space where a function keeps its names and values while it runs. Each call gets a new one.
tuple
A container that holds several items in a set order. You write it with parentheses, like (1, 2, 3).
indexable
Able to pick out one item by its position number, starting at 0 for the first item.

Example

Think of a tuple as a row of numbered lockers, where each locker holds one thing and the order of the lockers never changes. You can open locker 0, then locker 1, and so on. A function scope is like a separate desk for each job: when one job needs a result from another job, it pauses at its desk until the answer comes back.

3 checked practice questions for this part are in the app.

Part 3 · 20:00–30:00

This part explains tuples, a way to hold a fixed group of values in order, and shows how they can swap variables and return several values from a function.

Key ideas

Words to know

tuple
A fixed group of values written in parentheses and separated by commas. Once made, its values cannot be changed.
element
One item inside a tuple, string, or other group of values.
concatenate
To join two things end to end. Joining two tuples with plus makes one longer tuple.
iterate
To go through a group one item at a time, for example with a for loop.

Example

Think of a tuple like a sealed box with labeled slots. You can look at what is in each slot, but you cannot swap out an item inside. If you want different contents, you pack a new box instead.

3 checked practice questions for this part are in the app.

Part 4 · 30:00–40:00

This part shows how a function can hand back several answers at once using a tuple, how to count vowels and consonants with a loop, how a star lets a function take any number of inputs, and how lists are written.

Key ideas

Words to know

tuple
A fixed group of values held together in one object, written with parentheses, such as 3, 1.
quotient
The whole-number answer you get when one number is divided by another, such as 3 when you divide 10 by 3.
parameter
A name in a function's definition that stands for an input the function will receive when it is called.
list
An ordered group of values written with square brackets, similar to a tuple but written differently.

Example

Think of a lunch bag that holds a sandwich, an apple, and a juice box. You hand over one bag, but it carries three things inside, just as a function returns one tuple that carries several values. When you open the bag, you can take each item out and use it separately.

3 checked practice questions for this part are in the app.

Part 5 · 40:00–45:18

This part shows how lists are made, how they are similar to tuples and strings, and how loops can go through list items directly.

Key ideas

Words to know

element
One item inside a list, tuple, or string. For example, 8, 3, and 5 are the three elements of a list of numbers.
index
The position number of an item in a list, written inside square brackets to pick that item out.
loop variable
The name that holds one item at a time while a loop runs. In a for loop, it takes on each value in turn.
Pythonic
Written in the clear, short style that experienced Python programmers prefer.

Example

Think of a row of mailboxes. Looking at each mailbox in order is like a loop that goes through the items directly. Writing down the mailbox number first and then walking to it is like using an index, which takes more steps and is harder to follow.

3 checked practice questions for this part are in the app.

← Lecture 7: Decomposition, Abstraction, and Functions · Lecture 10: Lists and Mutability →

Notes written by AI (Claude) from the lecture's official transcript, so check anything important against the lecture. MIT OpenCourseWare · CC BY-NC-SA 4.0 · not affiliated with or endorsed by MIT. These notes are shared under the same license.

LessonBound · Free lecture notes · Privacy · Terms · New York