Topics A to Z
Python keywords, functions, methods, types and ideas from the lessons, A to Z, each in one line with the steps that teach it. It's a map of this course, not all of Python: for every function and module, see Python's library reference.
353 topics
Operators and symbols
operator!=Compares two values and gives
Truewhen they are not equal.- Comparison operators (module 5, Conditional statements)
- Drills in Deathmatch (topic: Conditional statements)
operator%Gives the remainder of a division, so
7 % 2is 1.- Arithmetic operators (module 4, Arithmetic operations)
- Drills in Deathmatch (topic: Arithmetic operations)
operator**Raises a number to a power, so
2 ** 3is 8.- Arithmetic operators (module 4, Arithmetic operations)
- Drills in Deathmatch (topic: Arithmetic operations)
*args
ideaA parameter with a star before its name, which collects any number of arguments into a tuple.
- Any number of arguments (module 32, More Python features)
- Drills in Deathmatch (topic: More Python features)
operator+=Adds to a variable, so
total += 5does the same astotal = total + 5.- Calculating with variables (module 4, Arithmetic operations)
- Drills in Deathmatch (topic: Arithmetic operations)
operator//Integer division, which divides and rounds the result down to a whole number, so
7 // 2is 3.- Arithmetic operators (module 4, Arithmetic operations)
- Types of results (module 4, Arithmetic operations)
- Drills in Deathmatch (topic: Arithmetic operations)
operator=Assignment, which works out the value on its right and stores it in the variable on its left.
- Variables (module 2, Information from the user)
- Changing a value (module 3, Variables and f-strings)
- Drills in Deathmatch (topic: Variables and f-strings)
operator==Compares two values and gives
Truewhen they are equal; a single=stores a value instead.- Comparison operators (module 5, Conditional statements)
- Drills in Deathmatch (topic: Conditional statements)
operator|Makes the union of two sets, a set of everything that is in either of them, as in
a | b;a |= bputs every item ofbintoa.- Challenge: the 0/1 knapsack (module 65, Dynamic programming)
- Drills in Deathmatch (topic: Dynamic programming)
A
functionabsReturns a number without its minus sign, so
abs(a - b)is the distance between two numbers.- The best item so far (module 16, Definite iteration)
access modifier
ideaThe level of access of an attribute or a method: public
name, protected_nameor private__name.- Protected attributes (module 42, Access modifiers)
- Drills in Deathmatch (topic: Access modifiers)
method__add__The method Python calls for
+, which usually returns a new object;__sub__and__mul__do the same for-and*.- Arithmetic operators (module 43, Object oriented programming techniques)
- Drills in Deathmatch (topic: Object oriented programming techniques)
adjacency list
ideaKeeps a graph as a dict or a list that maps each vertex to the list of its neighbors, in O(V + E) memory for V vertices and E edges.
- Graphs and adjacency lists (module 63, Graphs)
- Drills in Deathmatch (topic: Graphs)
alphabetical order
ideaStrings compare with
<and>character by character, so"car" < "cat"is true, and every capital letter comes before every small letter.- Comparing strings (module 7, More conditionals)
- Drills in Deathmatch (topic: More conditionals)
amortized time
ideaA cost averaged over a whole series of operations: n appends to a list take O(n) in all, so each is O(1) amortized, though a few of them are slow.
- Load factor and rehashing (module 61, Hash tables)
- Drills in Deathmatch (topic: Hash tables)
keywordandCombines two conditions into one that is true only when both of them are true.
- Both at once: and (module 8, Combining conditions)
- Drills in Deathmatch (topic: Combining conditions)
animation
ideaMovement made of frames that each draw things a little differently, such as an image whose position changes by a few pixels per frame.
- Moving pictures (module 54, Animation)
- Drills in Deathmatch (topic: Animation)
application logic
ideaThe part of a program that holds its data and the rules for handling it, apart from the user interface and the storage.
- Start with the application logic (module 44, Developing a larger application)
- Drills in Deathmatch (topic: Developing a larger application)
argument
ideaA value given to a function in the parentheses of its call, such as
"Hi"inprint("Hi").- Functions, arguments and return values (module 6, Programming terminology)
- Parameters and arguments (module 13, Defining functions)
- Drills in Deathmatch (topic: Programming terminology)
attribute
ideaA variable that belongs to an object, used with a dot after the object, such as
day.yearorself.name.- Classes are blueprints (module 33, Objects and methods)
- Your first class (module 34, Defining classes)
- Attributes of every kind (module 34, Defining classes)
- Drills in Deathmatch (topic: Defining classes)
exceptionAttributeErrorRaised when an object has no attribute or method of the name used, such as an attribute that was never set or a typo in its name.
- The interactive interpreter (module 14, More functions)
- Methods belong to objects (module 33, Objects and methods)
- Your first class (module 34, Defining classes)
- Drills in Deathmatch (topic: Defining classes)
B
backtracking
ideaTries the options one at a time with a recursive function: choose one, explore what follows from it, then take it back and try the next.
- Subsets: take it or leave it (module 64, Recursion and backtracking)
- The N queens (module 64, Recursion and backtracking)
- A sudoku solver (module 64, Recursion and backtracking)
- Drills in Deathmatch (topic: Recursion and backtracking)
balanced tree
ideaA tree in which the two subtrees of every node have about the same height, the number of nodes on the longest path down, so the whole tree is about log₂ n high.
- Binary trees and recursion (module 62, Trees and heaps)
- Binary search trees (module 62, Trees and heaps)
- Drills in Deathmatch (topic: Trees and heaps)
base case
ideaThe case in which a recursive function answers without calling itself, so that the calls stop.
- A function that calls itself (module 47, Recursion)
- Recursion that returns a value (module 47, Recursion)
- Drills in Deathmatch (topic: Recursion)
base class
ideaThe class that another class inherits from, which holds what its derived classes share.
- Inheriting from a base class (module 41, Class hierarchies)
- Drills in Deathmatch (topic: Class hierarchies)
Big-O notation
ideaSays how the work of a program grows with the size of its input, such as O(n) or O(n²), leaving out constant factors.
- Big-O in practice (module 59, Complexity and searching)
- Drills in Deathmatch (topic: Complexity and searching)
binary search
ideaFinds a value in a sorted list by looking at the middle item and going on in the half that can hold the value.
- Binary search (module 47, Recursion)
- Binary search (module 59, Complexity and searching)
- Drills in Deathmatch (topic: Recursion)
binary tree
ideaA branching structure of nodes in which each node has at most two children, a left one and a right one.
- Binary trees (module 48, More recursion examples)
- A sorted binary tree (module 48, More recursion examples)
- Binary trees and recursion (module 62, Trees and heaps)
- Drills in Deathmatch (topic: More recursion examples)
functionbisect.bisect_leftGives the index where a value would go in a sorted list, before any equal items, in O(log n);
bisect_rightgives the index after them.- Binary search (module 59, Complexity and searching)
- Drills in Deathmatch (topic: Complexity and searching)
block
ideaA group of statements one after another at the same indentation, such as the lines that run when the condition of an
ifis true.- Statements and blocks (module 6, Programming terminology)
- Conditions inside conditions (module 8, Combining conditions)
- Drills in Deathmatch (topic: Programming terminology)
typeboolThe type of the Boolean values
TrueandFalse, which every condition gives.- True and False (module 5, Conditional statements)
- Drills in Deathmatch (topic: Conditional statements)
breadth-first search
ideaSearches a graph or a tree level by level with a queue, finding everything one step from the start before anything two steps away, in O(V + E).
- Level order with a deque (module 62, Trees and heaps)
- Breadth-first search (module 63, Graphs)
- Drills in Deathmatch (topic: Graphs)
keywordbreakEnds the loop it is in at once, and the program goes on from the first line after the loop.
- Repeating with while True (module 9, Simple loops)
- Drills in Deathmatch (topic: Simple loops)
C
call stack
ideaThe unfinished function calls that Python keeps waiting, the newest on top, each carrying on when the call above it returns.
- Recursion that returns a value (module 47, Recursion)
chained comparison
ideaA comparison such as
1 <= x <= 10that compares the value in the middle with both limits at once.- Ranges and longer conditions (module 8, Combining conditions)
- Drills in Deathmatch (topic: Combining conditions)
character class
ideaSquare brackets in a regular expression, such as
[aeiou]or[0-9], which match one character of those listed.- Alternatives and character classes (module 52, Regular expressions)
- Drills in Deathmatch (topic: Regular expressions)
clamping
ideaKeeping a value between a lowest and a highest allowed value, for example a position inside the window with
max(0, min(x, WIDTH - 40)).- Planning your own game (module 58, Your own game)
- A complete small game (module 58, Your own game)
- Drills in Deathmatch (topic: Your own game)
keywordclassDefines a class, the blueprint for a kind of object: the attributes its objects get and the methods they have.
- Your first class (module 34, Defining classes)
- The constructor and self (module 34, Defining classes)
- Drills in Deathmatch (topic: Defining classes)
class hierarchy
ideaClasses that inherit one another over several levels, like a family tree, where an object is also an instance of every class above its own.
- Class hierarchies and isinstance (module 41, Class hierarchies)
- Drills in Deathmatch (topic: Class hierarchies)
class variable
ideaA variable written in a class outside its methods, shared by all objects of the class and used through the class's name.
- Class variables (module 40, Class attributes)
- Drills in Deathmatch (topic: Class attributes)
function@classmethodA decorator that makes a method belong to the class, so it's called through the class's name and gets the class as
cls.- Class methods and static methods (module 40, Class attributes)
- Drills in Deathmatch (topic: Class attributes)
client
ideaThe code that uses an object by creating it and calling its methods.
- Keeping the object valid (module 35, Defining methods)
- Private attributes (module 39, Encapsulation)
cls
ideaThe usual name of a class method's first parameter, which refers to the class itself, so
cls(...)creates a new object.- Class methods and static methods (module 40, Class attributes)
- Drills in Deathmatch (topic: Class attributes)
typecollections.CounterA dict that counts.
Counter(values)maps each value to how often it appears, a missing value counts as 0, andmost_common(k)gives the k most common.- Sets and dicts for speed (module 59, Complexity and searching)
typecollections.dequeA queue that adds and removes items at both of its ends in O(1), with
appendandpopleft, where a list'spop(0)is O(n).- Level order with a deque (module 62, Trees and heaps)
- Breadth-first search (module 63, Graphs)
- Drills in Deathmatch (topic: Trees and heaps)
typecollections.OrderedDictA dict that moves a key to its end with
move_to_end(key)and removes its first pair withpopitem(last=False), both in O(1) on average.- Challenge: an LRU cache (module 61, Hash tables)
- Drills in Deathmatch (topic: Hash tables)
collision detection
ideaFinding out whether two things in a game touch, such as the robot and a coin, often by checking whether their rectangles overlap.
- Planning your own game (module 58, Your own game)
- Drills in Deathmatch (topic: Your own game)
combination
ideaA choice of k items in which the order doesn't matter; a search makes each one only once by picking the items in increasing order.
- Combinations and pruning (module 64, Recursion and backtracking)
- Drills in Deathmatch (topic: Recursion and backtracking)
comparison operator
ideaOne of
==,!=,<,<=,>and>=, which compare two values and giveTrueorFalse.- Comparison operators (module 5, Conditional statements)
- Drills in Deathmatch (topic: Conditional statements)
concatenation
ideaJoining strings end to end with
+, which puts nothing between them, not even a space.- Joining strings with + (module 2, Information from the user)
- Drills in Deathmatch (topic: Information from the user)
conditional expression
ideaChooses between two values in one line, as in
"warm" if temperature > 20 else "cold".- Conditional expressions (module 32, More Python features)
- Drills in Deathmatch (topic: More Python features)
constructor
ideaThe call that makes a new object, the class's name with parentheses, which runs the class's
__init__method to set the object up.- Classes are blueprints (module 33, Objects and methods)
- The constructor and self (module 34, Defining classes)
- Drills in Deathmatch (topic: Defining classes)
keywordcontinueSkips the rest of the current round of a loop and goes straight back to the loop's condition.
- Skipping a round with continue (module 12, More loops)
- Drills in Deathmatch (topic: More loops)
coordinates
ideaIn pygame, (0, 0) is the top-left corner of the window, x grows to the right and y grows downward.
- Images and coordinates (module 53, Pygame)
- Drills in Deathmatch (topic: Pygame)
counting sort
ideaSorts small whole numbers without comparing them, by counting how many times each value appears: O(n + k) for n values from 0 to k.
- Counting sort (module 60, Sorting algorithms)
- Drills in Deathmatch (topic: Sorting algorithms)
CSV
ideaA text file format where each line is one record and its fields are separated by a character such as a comma or a semicolon.
- Lines with several values (module 23, Reading files)
- Writing CSV files (module 24, Writing files)
- Drills in Deathmatch (topic: Reading files)
modulecsvReads CSV files with
csv.reader, which gives each line as a list of values and understands values in quotes.- The csv module (module 30, Data processing)
- Drills in Deathmatch (topic: Data processing)
D
data type
ideaThe kind of a value, such as
int,float,strorbool, which decides what operators like+do with it.- Expressions, values and types (module 6, Programming terminology)
- Drills in Deathmatch (topic: Programming terminology)
moduledatetimeDates and times, with the type
datetimefor a moment, as indatetime(2026, 3, 14, 9, 5), andtimedeltafor a length of time.- Dates and times (module 29, Times and dates)
- Comparing and calculating with dates (module 29, Times and dates)
- Formatting and reading dates (module 29, Times and dates)
- Drills in Deathmatch (topic: Times and dates)
methoddatetime.strftimeTurns a datetime into text in the format you describe with codes such as
%d,%m,%Y,%Hand%M.- Formatting and reading dates (module 29, Times and dates)
- Drills in Deathmatch (topic: Times and dates)
methoddatetime.strptimeReads a date written as text in a given format, such as
"%d.%m.%Y", and makes a datetime of it.- Formatting and reading dates (module 29, Times and dates)
- Drills in Deathmatch (topic: Times and dates)
debugging
ideaFinding and fixing bugs, often with debugging prints that show the values of variables and conditions as the program runs.
- Errors and debugging (module 6, Programming terminology)
- Debugging loops with print (module 9, Simple loops)
- Drills in Deathmatch (topic: Simple loops)
decorator
ideaA line that starts with
@just above adef, such as@property, which changes how the method is used.- Getters with @property (module 39, Encapsulation)
- Class methods and static methods (module 40, Class attributes)
- Drills in Deathmatch (topic: Encapsulation)
keyworddefStarts a function definition, with the function's name, its parameters in parentheses and a colon.
- Your own functions (module 13, Defining functions)
- Parameters and arguments (module 13, Defining functions)
- Drills in Deathmatch (topic: Defining functions)
default parameter value
ideaA value written with
=after a parameter's name in thedefline, used when a call leaves that argument out.- Default parameter values (module 32, More Python features)
- Drills in Deathmatch (topic: More Python features)
keyworddelRemoves a key and its value from a dictionary, as in
del ages["Ada"].- Removing keys (module 21, Dictionary)
- Drills in Deathmatch (topic: Dictionary)
dependency injection
ideaGiving an object the things it depends on from outside, such as passing a file handler to the application's constructor.
- Reading and saving the data (module 44, Developing a larger application)
- Drills in Deathmatch (topic: Developing a larger application)
depth-first search
ideaSearches a graph by following one way as far as it goes before backing up, with recursion or a stack of your own, in O(V + E).
- Depth-first search and flood fill (module 63, Graphs)
- Drills in Deathmatch (topic: Graphs)
derived class
ideaA class that inherits another class and adds or changes attributes and methods of its own.
- Inheriting from a base class (module 41, Class hierarchies)
- Drills in Deathmatch (topic: Class hierarchies)
typedictA dictionary: pairs of keys and values, written as
{"tea": 2.0}, in which each value is found by its key.- Keys and values (module 21, Dictionary)
- What a dictionary can hold (module 21, Dictionary)
- Buckets and chaining (module 61, Hash tables)
- Drills in Deathmatch (topic: Dictionary)
methoddict.clearRemoves every key and value from a dictionary, leaving it empty.
- Removing keys (module 21, Dictionary)
- Drills in Deathmatch (topic: Dictionary)
methoddict.itemsGives the keys of a dictionary together with their values, for a loop such as
for key, value in prices.items():.- Going through a dictionary (module 21, Dictionary)
- Tuples without parentheses (module 22, Tuple)
- Drills in Deathmatch (topic: Dictionary)
methoddict.popRemoves a key from a dictionary and returns its value; with a second argument, it returns that argument when the key is missing.
- Removing keys (module 21, Dictionary)
- Drills in Deathmatch (topic: Dictionary)
dictionary comprehension
ideaBuilds a new dictionary in a single expression, such as
{word: len(word) for word in words}.- Dictionary comprehensions (module 46, More comprehensions)
- Drills in Deathmatch (topic: More comprehensions)
functiondifflib.get_close_matchesReturns the strings of a list that look most like a given word, the most similar first, as for suggesting a fix to a typo.
- Finding the right module (module 30, Data processing)
- Drills in Deathmatch (topic: Data processing)
Dijkstra's algorithm
ideaFinds the cheapest way from a start to every vertex of a graph whose edges have weights, none of them negative, with a heap, in O((V + E) log V).
- Dijkstra's shortest paths (module 63, Graphs)
- Drills in Deathmatch (topic: Graphs)
draw order
ideaThe order in which a program draws on the window; whatever is drawn later covers what was drawn before, so tiles come before the things that stand on them.
- Moving the robot (module 57, Game project)
- Drills in Deathmatch (topic: Game project)
dynamic programming
ideaBuilds an answer from the answers to smaller questions of the same kind, working out each one only once, top down with a memo or bottom up with a table.
- Memoization (module 65, Dynamic programming)
- Bottom-up tables (module 65, Dynamic programming)
- Drills in Deathmatch (topic: Dynamic programming)
E
early return
ideaA
returnin the middle of a function or method, which ends it at once, for example when a check finds that there's nothing to do.- Moving the robot (module 57, Game project)
- Drills in Deathmatch (topic: Game project)
edit distance
ideaThe fewest one-character inserts, deletes and replaces that turn one string into another, found with a table of their prefixes in O(n × m) time.
- Longest common subsequence and edit distance (module 65, Dynamic programming)
- Drills in Deathmatch (topic: Dynamic programming)
keywordelifAdds a branch with its own condition to an
ifstatement, checked only when the conditions before it are false.- More branches with elif (module 7, More conditionals)
- The order of conditions (module 7, More conditionals)
- Drills in Deathmatch (topic: More conditionals)
keywordelseStarts the branch of a conditional statement that runs when none of the conditions before it is true.
- Two branches with else (module 7, More conditionals)
- Drills in Deathmatch (topic: More conditionals)
empty string
ideaThe string
""with no characters in it, of length 0, often the starting value of a string that a loop builds up.- Functions, arguments and return values (module 6, Programming terminology)
- Building strings in a loop (module 9, Simple loops)
- Drills in Deathmatch (topic: Simple loops)
encapsulation
ideaKeeping an object's data valid by handling it only through the object's own methods, which hide the details from the client.
- Keeping the object valid (module 35, Defining methods)
- Private attributes (module 39, Encapsulation)
- Getters with @property (module 39, Encapsulation)
- Drills in Deathmatch (topic: Defining methods)
functionenumerateGives each item of a list together with its index, as in
for i, x in enumerate(values):, in place ofrange(len(values)).- Sets and dicts for speed (module 59, Complexity and searching)
- Drills in Deathmatch (topic: Complexity and searching)
method__eq__The method Python calls for
==andin, without which==only checks whether two names refer to the same object.- Equality with __eq__ (module 43, Object oriented programming techniques)
- Hashing your own keys (module 61, Hash tables)
- Drills in Deathmatch (topic: Object oriented programming techniques)
event
ideaSomething that happens to a pygame program, such as a key press or a click, with a type like
pygame.KEYDOWNand attributes likekeyorpos.- A window of your own (module 53, Pygame)
- Events and key presses (module 55, Events)
- The mouse (module 55, Events)
- Drills in Deathmatch (topic: Events)
keywordexceptStarts the block that runs when the code in the
tryblock raises the kind of exception theexceptline names.- Catching errors with try and except (module 25, Handling errors)
- Different kinds of errors (module 25, Handling errors)
- Raising errors yourself (module 25, Handling errors)
- Drills in Deathmatch (topic: Handling errors)
exception
ideaAn error that happens while a program runs, which stops the program unless a
tryandexcepthandle it.- Catching errors with try and except (module 25, Handling errors)
- Different kinds of errors (module 25, Handling errors)
- How errors move from function to function (module 25, Handling errors)
- Drills in Deathmatch (topic: Handling errors)
expression
ideaA piece of code that Python evaluates to a value, such as
2 + 3, a variable, a comparison or a function call.- Expressions, values and types (module 6, Programming terminology)
- Drills in Deathmatch (topic: Programming terminology)
F
f-string
ideaA string with
fbefore its opening quote, in which each value in curly brackets is put into the text.- F-strings (module 3, Variables and f-strings)
- Drills in Deathmatch (topic: Variables and f-strings)
factorial
ideaThe product of the whole numbers from 1 to n, written n!, a classic example of a recursive function.
- Recursion that returns a value (module 47, Recursion)
literalFalseOne of the two Boolean values, the value of a condition that doesn't hold; it is written with a capital F.
- True and False (module 5, Conditional statements)
- Drills in Deathmatch (topic: Conditional statements)
Fibonacci sequence
ideaThe numbers 1, 1, 2, 3, 5, 8 and so on, where each number is the sum of the two before it; some start from 0, as 0, 1, 1, 2, 3.
- Fibonacci, strings and lists (module 47, Recursion)
- Memoization (module 65, Dynamic programming)
file handle
ideaThe variable through which a program reads or writes an open file, such as
fileinwith open("notes.txt") as file:.- Opening and reading a file (module 23, Reading files)
- Drills in Deathmatch (topic: Reading files)
file mode
ideaThe second argument of
open, which says what the program does with the file, such as"w"to write a new file or"a"to add to its end.- Creating and writing a file (module 24, Writing files)
- Adding to the end of a file (module 24, Writing files)
- Drills in Deathmatch (topic: Writing files)
methodfile.readReads everything that's left in an open file and returns it as one string, line breaks included.
- Opening and reading a file (module 23, Reading files)
- Drills in Deathmatch (topic: Reading files)
methodfile.writeWrites a string into a file opened for writing or appending, adding no line break of its own.
- Creating and writing a file (module 24, Writing files)
- Writing CSV files (module 24, Writing files)
- Drills in Deathmatch (topic: Writing files)
exceptionFileNotFoundErrorRaised when a program tries to open a file that doesn't exist.
- Opening and reading a file (module 23, Reading files)
- Different kinds of errors (module 25, Handling errors)
- Drills in Deathmatch (topic: Handling errors)
functionfilterGives, as an iterator, the items of a series for which a function returns
True.- Selecting with filter (module 51, Functional programming)
- Drills in Deathmatch (topic: Functional programming)
filtering
ideaKeeping only the items that meet a condition, as an
ifat the end of a comprehension does.- Picking items with if (module 45, List comprehensions)
- Drills in Deathmatch (topic: List comprehensions)
typefloatThe type of numbers with a decimal point, such as
2.5;float(...)turns a string such as"2.5"into a float.- Floating point numbers (module 3, Variables and f-strings)
- Numbers as input (module 4, Arithmetic operations)
- Drills in Deathmatch (topic: Variables and f-strings)
keywordforStarts a loop that goes through the items of a list, the characters of a string or the numbers of a range, one at a time.
- Going through a list with for (module 16, Definite iteration)
- Going through a string (module 16, Definite iteration)
- Drills in Deathmatch (topic: Definite iteration)
format specifier
ideaThe part after a colon inside an f-string's braces that sets how a value is shown, such as
{price:.2f}for two decimals or{name:<10}for a width.- Decimals in f-strings (module 17, Print statement formatting)
- Widths and alignment (module 17, Print statement formatting)
- Drills in Deathmatch (topic: Print statement formatting)
typeFractionA class of the
fractionsmodule for exact fractions, such asFraction(3, 4), with the attributesnumeratoranddenominator.- Classes are blueprints (module 33, Objects and methods)
- Drills in Deathmatch (topic: Objects and methods)
modulefractionsThe module with the class
Fraction, for fractions that are exact where floating point numbers can be slightly off.- Classes are blueprints (module 33, Objects and methods)
frame
ideaOne picture that a pygame window shows when the program calls
pygame.display.flip(); an animation is many frames that each differ a little.- A window of your own (module 53, Pygame)
- Moving pictures (module 54, Animation)
- Drills in Deathmatch (topic: Animation)
keywordfromImports chosen names from a module straight into the program, as in
from math import sqrt, so they work without the module's name in front.- Importing names with from (module 27, Modules)
- Drills in Deathmatch (topic: Modules)
function call
ideaRunning a function by writing its name with parentheses after it, with the arguments, if any, inside them.
- Calling functions (module 13, Defining functions)
- Drills in Deathmatch (topic: Defining functions)
functional programming
ideaA style of programming that builds a program from functions that return new values, instead of changing variables step by step.
- Transforming with map (module 51, Functional programming)
- Drills in Deathmatch (topic: Functional programming)
modulefunctoolsA module of tools for working with functions, such as
reduce,cacheandlru_cache.- Combining with reduce (module 51, Functional programming)
- Challenge: an LRU cache (module 61, Hash tables)
- Memoization (module 65, Dynamic programming)
- Drills in Deathmatch (topic: Functional programming)
functionfunctools.cacheA decorator that memoizes a function: with
@cacheabove itsdef, every result is kept by its arguments, which must be hashable.- Memoization (module 65, Dynamic programming)
- Drills in Deathmatch (topic: Dynamic programming)
functionfunctools.lru_cacheA decorator that remembers a function's results for the arguments it was called with, keeping at most
maxsizeof them and pushing out the least recently used.- Challenge: an LRU cache (module 61, Hash tables)
- Drills in Deathmatch (topic: Hash tables)
functionfunctools.reduceCombines the items of a series into one value by calling a function with the result so far and each item in turn.
- Combining with reduce (module 51, Functional programming)
- Drills in Deathmatch (topic: Functional programming)
G
game map
ideaA game's level kept as data, such as a list of strings with one character per square, which the program reads as
level[y][x]and draws tile by tile.- The game map (module 57, Game project)
- Drills in Deathmatch (topic: Game project)
game phase
ideaWhich part of a game is going on, such as playing or game over, kept in an attribute that the main loop and the drawing check.
- A complete small game (module 58, Your own game)
- Drills in Deathmatch (topic: Your own game)
generator
ideaAn object that produces the values of a series one at a time, only when they are asked for, made by a generator function or a generator expression.
- Generator functions and yield (module 50, Generators)
- next and StopIteration (module 50, Generators)
- Drills in Deathmatch (topic: Generators)
generator expression
ideaA comprehension in round brackets, such as
(n * n for n in numbers), which makes a generator instead of a list.- Generator expressions (module 50, Generators)
- Drills in Deathmatch (topic: Generators)
method__getitem__The method Python calls for
m[key], as it calls__setitem__,__delitem__,__contains__and__len__for storing,del,inandlen.- A map that works like dict (module 61, Hash tables)
- Drills in Deathmatch (topic: Hash tables)
getter
ideaA method that gives the value of an attribute, in Python usually written with
@property.- Getters with @property (module 39, Encapsulation)
- Drills in Deathmatch (topic: Encapsulation)
keywordglobalglobal nameat the start of a function makesnamemean the global variable, so the function can assign a new value to it.- The global keyword (module 26, Local and global variables)
- Drills in Deathmatch (topic: Local and global variables)
global variable
ideaA variable made in the main program, outside every function, which a function can read but should get as a parameter instead.
- Parameters, not outside variables (module 13, Defining functions)
- Local variables (module 26, Local and global variables)
- The global keyword (module 26, Local and global variables)
- Drills in Deathmatch (topic: Defining functions)
graph
ideaA set of vertices (the things) and edges (the links between pairs of them); edges can go one way only, and they can have weights.
- Graphs and adjacency lists (module 63, Graphs)
- Drills in Deathmatch (topic: Graphs)
greedy algorithm
ideaTakes the choice that looks best right now and never goes back: right for fitting the most meetings, but it can miss the best answer, as with the coins 1, 4 and 5 for 8.
- Python's sort: keys and stability (module 60, Sorting algorithms)
- Coin change (module 65, Dynamic programming)
- Drills in Deathmatch (topic: Dynamic programming)
grid coordinates
ideaA place counted in squares of a grid, column x and row y, which becomes a point in pixels when each is multiplied by the size of a square, as in
(x * SIZE, y * SIZE).- The game map (module 57, Game project)
- Moving the robot (module 57, Game project)
- Drills in Deathmatch (topic: Game project)
H
hash
ideaA number Python makes from a key to find it fast; a list has none, as it can change. A class with
__eq__needs a__hash__that gives equal objects equal hashes.- What a dictionary can hold (module 21, Dictionary)
- Hashing your own keys (module 61, Hash tables)
- Drills in Deathmatch (topic: Dictionary)
hash collision
ideaTwo keys that land in the same bucket of a hash table; collisions can't be avoided, and if every key collides, each lookup takes O(n).
- Buckets and chaining (module 61, Hash tables)
- Hashing your own keys (module 61, Hash tables)
- Drills in Deathmatch (topic: Hash tables)
hash table
ideaKeeps keys in buckets picked by each key's hash, so that finding, adding and removing a key take O(1) on average;
dictandsetare hash tables.- Buckets and chaining (module 61, Hash tables)
- Load factor and rehashing (module 61, Hash tables)
- Drills in Deathmatch (topic: Hash tables)
heap
ideaA tree kept in a list with every parent no bigger than its children, so the smallest item is at index 0, and adding an item or removing the smallest takes O(log n).
- Heaps and heapq (module 62, Trees and heaps)
- Drills in Deathmatch (topic: Trees and heaps)
moduleheapqKeeps a heap in a plain list, with
heappush,heappopandheapify, and finds the k smallest or largest items withnsmallestandnlargest.- The k smallest and the median (module 60, Sorting algorithms)
- Heaps and heapq (module 62, Trees and heaps)
- Drills in Deathmatch (topic: Trees and heaps)
functionheapq.heappushAdds an item to a heap in O(log n), keeping the smallest at index 0;
heapq.heappopremoves and returns the smallest, also in O(log n).- Heaps and heapq (module 62, Trees and heaps)
- Dijkstra's shortest paths (module 63, Graphs)
- Drills in Deathmatch (topic: Trees and heaps)
helper method
ideaA method that the constructor or the other methods of a class call through
selfto do part of their work.- Helper methods and local variables (module 35, Defining methods)
- Drills in Deathmatch (topic: Defining methods)
helper variable
ideaA variable that keeps track of something while a loop runs, such as a count or a total, set to its starting value before the loop.
- Helper variables: counting and summing (module 9, Simple loops)
- Building strings in a loop (module 9, Simple loops)
- Drills in Deathmatch (topic: Simple loops)
I
keywordifStarts a conditional statement, which runs the indented block below it only when its condition is true.
- The if statement (module 5, Conditional statements)
- Conditions at work (module 5, Conditional statements)
- Drills in Deathmatch (topic: Conditional statements)
immutable
ideaAn immutable value, such as a number, a string or a tuple, can't change after it's made, so operations on it make a new value instead.
- Two names for one list (module 20, References)
- What a tuple is (module 22, Tuple)
- Drills in Deathmatch (topic: References)
keywordimportLoads a module so that the program can use the functions and values in it, as in
import math.- Importing a module (module 27, Modules)
- Importing names with from (module 27, Modules)
- A program of several files (module 31, Creating your own modules)
- Drills in Deathmatch (topic: Modules)
keywordinChecks whether one string is part of another, so
part in textisTruewhentextcontainspart.- Searching in a string (module 11, Working with strings)
- Drills in Deathmatch (topic: Working with strings)
indentation
ideaThe spaces at the start of a line, which tell Python which lines belong to a block; four spaces is the standard.
- Indentation and blocks (module 5, Conditional statements)
- Drills in Deathmatch (topic: Conditional statements)
exceptionIndentationErrorPython stops with it before running anything when a line's indentation doesn't fit, such as an unindented line after a colon.
- Indentation and blocks (module 5, Conditional statements)
- Drills in Deathmatch (topic: Conditional statements)
index
ideaThe number that tells where a character is in a string, counting from 0 for the first character.
- One character at a time (module 11, Working with strings)
- Counting from the end (module 11, Working with strings)
- Drills in Deathmatch (topic: Working with strings)
exceptionIndexErrorThe error Python stops with when an index is outside the indexes that a string has.
- One character at a time (module 11, Working with strings)
- Counting from the end (module 11, Working with strings)
- Drills in Deathmatch (topic: Working with strings)
infinite loop
ideaA loop that never ends because no
breakcan ever run, for example when the value it checks never changes.- Repeating with while True (module 9, Simple loops)
- Drills in Deathmatch (topic: Simple loops)
inheritance
ideaA class taking over the attributes and methods of another class, as in
class Wizard(Character):, so that shared code is written only once.- Inheriting from a base class (module 41, Class hierarchies)
- Drills in Deathmatch (topic: Class hierarchies)
method__init__The constructor method of a class, which Python calls to set up each new object, with the object as
self.- The constructor and self (module 34, Defining classes)
- Drills in Deathmatch (topic: Defining classes)
initialization
ideaGiving a variable its first value before a loop, so that the loop's condition can use it in the first round.
- Start, condition, update (module 10, Loops with conditions)
- Drills in Deathmatch (topic: Loops with conditions)
functioninputShows its prompt, waits for the user to type a line and gives that line as a string.
- Asking the user (module 2, Information from the user)
- Numbers as input (module 4, Arithmetic operations)
- Drills in Deathmatch (topic: Information from the user)
input validation
ideaChecking that a value a program gets, such as typed input, makes sense before the program uses it.
- Checking input before using it (module 25, Handling errors)
- Drills in Deathmatch (topic: Handling errors)
insertion sort
ideaSorts a list by taking the items one at a time and sliding each one left past the bigger ones: O(n²) in general, but O(n) on a nearly sorted list.
- Insertion sort (module 60, Sorting algorithms)
- Drills in Deathmatch (topic: Sorting algorithms)
instance
ideaAn object made from a class;
Fraction(1, 2)is an instance of the classFraction.- Classes are blueprints (module 33, Objects and methods)
instance variable
ideaAn attribute that each object has for itself, created with
self.in a method such as__init__.- Class variables (module 40, Class attributes)
- Drills in Deathmatch (topic: Class attributes)
typeintThe type of whole numbers, such as
-15and2026;int(...)turns a string of digits or a float into an integer.- Numbers and strings (module 3, Variables and f-strings)
- Numbers as input (module 4, Arithmetic operations)
- Drills in Deathmatch (topic: Arithmetic operations)
interactive interpreter
toolPython's line by line mode, started with
python3in a terminal, which runs each line as soon as you type it after the>>>prompt and shows its value.- The interactive interpreter (module 14, More functions)
- Drills in Deathmatch (topic: More functions)
interval
ideaA pair
(start, end)such as a meeting. Sorted by start, the intervals that overlap merge in one pass; sorted by end, a greedy pass fits the most.- Python's sort: keys and stability (module 60, Sorting algorithms)
inversion
ideaA pair of items in the wrong order, a bigger one before a smaller one; insertion sort makes one move for each, and merge sort can count them in O(n log n).
- Insertion sort (module 60, Sorting algorithms)
- Merge sort (module 60, Sorting algorithms)
- Drills in Deathmatch (topic: Sorting algorithms)
operatorisChecks whether two names refer to the very same object, while
==checks whether two values are equal.- Two names for one object (module 37, Objects and references)
- Drills in Deathmatch (topic: Objects and references)
operatoris notThe opposite of
is, true when two names refer to different objects, as inif result is not None:.- Two names for one object (module 37, Objects and references)
- None: no object (module 38, Objects as attributes)
- Drills in Deathmatch (topic: Objects as attributes)
functionisinstanceTells whether a value is an object of a class or of a class derived from it, as in
isinstance(spark, Car).- Class hierarchies and isinstance (module 41, Class hierarchies)
- Equality with __eq__ (module 43, Object oriented programming techniques)
- Drills in Deathmatch (topic: Class hierarchies)
method__iter__Runs when a
forloop starts going through an object, and returns the iterator that hands out the items, often the object itself.- Iterators (module 43, Object oriented programming techniques)
- A map that works like dict (module 61, Hash tables)
- Drills in Deathmatch (topic: Object oriented programming techniques)
iterable
ideaA value that a
forloop can go through, such as a list, a string, or an object of a class with the methods__iter__and__next__.- Iterators (module 43, Object oriented programming techniques)
- Drills in Deathmatch (topic: Object oriented programming techniques)
iteration
ideaOne run through the block of a loop, after which Python goes back to the start of the loop for the next one.
- Repeating with while True (module 9, Simple loops)
- Drills in Deathmatch (topic: Simple loops)
iterative
ideaDescribes a solution that repeats with a loop, as opposed to a recursive one.
- A function that calls itself (module 47, Recursion)
iterator
ideaAn object that gives the values of a series one at a time and is used up after one pass, like the results of
map,filterand generators.- Iterators (module 43, Object oriented programming techniques)
- Transforming with map (module 51, Functional programming)
- Selecting with filter (module 51, Functional programming)
- Drills in Deathmatch (topic: Functional programming)
functionitertools.accumulateGives the running totals of a list, so
list(accumulate([5, 2, 7], initial=0))is[0, 5, 7, 14], the prefix sums.- Prefix sums (module 59, Complexity and searching)
- Drills in Deathmatch (topic: Complexity and searching)
functionitertools.permutationsGives every ordering of the items as tuples, such as
('a', 'b')and('b', 'a'); n items give n! of them.- Permutations (module 64, Recursion and backtracking)
- Drills in Deathmatch (topic: Recursion and backtracking)
J
modulejsonTurns JSON text into Python lists and dictionaries with
json.loads, orjson.loadfor an open file.- Reading JSON files (module 30, Data processing)
- Drills in Deathmatch (topic: Data processing)
K
Kadane's algorithm
ideaFinds the biggest sum of a stretch of values in a row, negative values too, in O(n), by keeping the best sum of a stretch that ends at each value.
- Prefix sums (module 59, Complexity and searching)
key
ideaWhat a dictionary stores a value under and finds it by; each key is in a dictionary once and can't be a list.
- Keys and values (module 21, Dictionary)
- What a dictionary can hold (module 21, Dictionary)
- Drills in Deathmatch (topic: Dictionary)
key function
ideaA function given to
sorted,sort,minormaxwithkey=, which returns the value each item is compared by.- Sorting with a key function (module 49, Functions as arguments)
- Sorting your own objects (module 49, Functions as arguments)
- Drills in Deathmatch (topic: Functions as arguments)
exceptionKeyErrorThe error Python raises when you read, update or delete a key that isn't in the dictionary.
- Keys and values (module 21, Dictionary)
- Counting and grouping (module 21, Dictionary)
- A map that works like dict (module 61, Hash tables)
- Drills in Deathmatch (topic: Dictionary)
keyword argument
ideaAn argument given with its parameter's name, such as
level=5, so it can skip parameters that have default values.- Default parameter values (module 32, More Python features)
- Default values for parameters (module 40, Class attributes)
- Drills in Deathmatch (topic: Class attributes)
knapsack problem
ideaChoosing items, each whole or not at all, for the most value within a weight limit; a table of items by capacity solves it in O(n × capacity).
- Challenge: the 0/1 knapsack (module 65, Dynamic programming)
- Drills in Deathmatch (topic: Dynamic programming)
L
keywordlambdaMakes a small function without a name, written
lambda parameters: expression, which returns the value of the expression.- Lambda expressions (module 49, Functions as arguments)
- Sorting your own objects (module 49, Functions as arguments)
- Drills in Deathmatch (topic: Functions as arguments)
leaf
ideaA node of a tree that has no children.
- Binary trees (module 48, More recursion examples)
functionlenGives the number of characters in a string, spaces and punctuation included.
- Functions, arguments and return values (module 6, Programming terminology)
- Building strings in a loop (module 9, Simple loops)
- The length of a string (module 11, Working with strings)
- Drills in Deathmatch (topic: Programming terminology)
line break
ideaThe character
\nthat ends each line of a text file, which a program reads as part of the line and must write itself withwrite.- Going through a file line by line (module 23, Reading files)
- Creating and writing a file (module 24, Writing files)
- Drills in Deathmatch (topic: Reading files)
linear search
ideaFinds a value by looking at the items one by one from the start.
- Binary search (module 47, Recursion)
linked list
ideaA chain of nodes, each with a value and a link to the next node. It adds a node at its front in O(1), but reaching the k-th node takes k steps.
- Binary trees and recursion (module 62, Trees and heaps)
- Challenge: an LRU cache (module 61, Hash tables)
typelistAn ordered collection of values in square brackets, such as
[18, 21, 17], whose items can be read and changed by their index.- Lists and indexes (module 15, Lists)
- Lists as arguments and return values (module 15, Lists)
- Drills in Deathmatch (topic: Lists)
list comprehension
ideaBuilds a new list from a series in a single expression, such as
[n * 2 for n in numbers].- A new list from an old one (module 45, List comprehensions)
- Comprehensions instead of loops (module 45, List comprehensions)
- Drills in Deathmatch (topic: List comprehensions)
list of lists
ideaA list whose items are lists, read with two indexes in a row, as in
teams[1][0]for the first item of the second list.- Lists inside lists (module 19, More lists)
- Copying a list (module 20, References)
- Paths through a grid (module 65, Dynamic programming)
- Drills in Deathmatch (topic: More lists)
methodlist.appendAdds an item to the end of a list.
- Adding items: append and insert (module 15, Lists)
- Drills in Deathmatch (topic: Lists)
methodlist.copyReturns a new list with the same items, so changing the copy leaves the original alone.
- Copying a list (module 20, References)
- Drills in Deathmatch (topic: References)
methodlist.insertAdds an item at the index you give, as in
queue.insert(0, item), and moves the items from that index on one place to the right.- Adding items: append and insert (module 15, Lists)
- Drills in Deathmatch (topic: Lists)
methodlist.popRemoves the item at the index you give, or the last item without an index, and returns the removed item.
- Removing items: pop and remove (module 15, Lists)
- Drills in Deathmatch (topic: Lists)
methodlist.removeRemoves the first item that has the value you give, and stops with a
ValueErrorif no item has it.- Removing items: pop and remove (module 15, Lists)
- Drills in Deathmatch (topic: Lists)
methodlist.sortSorts a list in place, from smallest to greatest or alphabetically, and returns
None.- Sorting: sort and sorted (module 15, Lists)
- Python's sort: keys and stability (module 60, Sorting algorithms)
- Drills in Deathmatch (topic: Lists)
load factor
ideaThe number of keys in a hash table divided by its number of buckets; when it passes a limit, the table grows and moves every key to its new bucket, which is rehashing.
- Load factor and rehashing (module 61, Hash tables)
- Drills in Deathmatch (topic: Hash tables)
local variable
ideaA variable created inside a function, its parameters included, which exists only inside that function while it runs.
- Local variables (module 26, Local and global variables)
- Drills in Deathmatch (topic: Local and global variables)
longest common subsequence
ideaThe longest string you can get from both of two strings by crossing out characters, found with a table of their prefixes in O(n × m) time.
- Longest common subsequence and edit distance (module 65, Dynamic programming)
- Drills in Deathmatch (topic: Dynamic programming)
loop condition
ideaThe condition after
while, which Python checks before every round of the loop; the loop runs as long as it is true.- A loop with a condition (module 10, Loops with conditions)
- Writing conditions (module 10, Loops with conditions)
- Drills in Deathmatch (topic: Loops with conditions)
loop else
ideaAn
elseblock after afororwhileloop, lined up with the loop, which runs when the loop ends withoutbreak.- pass, and loops with else (module 32, More Python features)
- Drills in Deathmatch (topic: More Python features)
LRU cache
ideaA cache that, when it's full, throws out the item that was used longest ago; an
OrderedDictkeeps the order of use in O(1) on average.- Challenge: an LRU cache (module 61, Hash tables)
- Drills in Deathmatch (topic: Hash tables)
method__lt__The method Python calls for
<, whichsorted,minandmaxuse too;__gt__,__le__and__ge__do the same for>,<=and>=.- Comparing objects with operators (module 43, Object oriented programming techniques)
- Equality with __eq__ (module 43, Object oriented programming techniques)
- Python's sort: keys and stability (module 60, Sorting algorithms)
- Drills in Deathmatch (topic: Object oriented programming techniques)
M
magic number
ideaA number in code whose meaning the reader has to know or guess, such as 3 for a box; a name or a character that looks like what it means is clearer.
- Pushing boxes (module 57, Game project)
- Drills in Deathmatch (topic: Game project)
main block
ideaThe code under
if __name__ == "__main__":at the end of a file, which runs when you run the file but not when a check loads it to call your functions.- Trying out your functions (module 14, More functions)
- Drills in Deathmatch (topic: More functions)
main loop
ideaThe
while Trueloop of a game, which in every round handles the events, updates the game's state, draws the picture and shows it as a frame.- A window of your own (module 53, Pygame)
- A small game (module 56, More pygame techniques)
- Drills in Deathmatch (topic: Pygame)
functionmapCalls a function on every item of a series and gives the results as an iterator, so
list(map(int, texts))makes a list of numbers.- Transforming with map (module 51, Functional programming)
- Selecting with filter (module 51, Functional programming)
- Drills in Deathmatch (topic: Functional programming)
methodMatch.groupGives the text that a regular expression matched, from the match object that
re.searchorre.fullmatchreturns.- What regular expressions are (module 52, Regular expressions)
- Drills in Deathmatch (topic: Regular expressions)
modulemathMathematical functions and values, such as
math.sqrt,math.floor,math.ceil,math.piandmath.inf, a float bigger than every finite number.- Importing a module (module 27, Modules)
- Importing names with from (module 27, Modules)
- Coin change (module 65, Dynamic programming)
- Drills in Deathmatch (topic: Modules)
functionmath.ceilRounds a number up to a whole number, so
math.ceil(2.1)is 3, which is handy when leftovers still need a place of their own.- Importing a module (module 27, Modules)
- Drills in Deathmatch (topic: Modules)
functionmath.sinGives the sine of an angle in radians; with
math.cos, it gives the point at that angle on a circle.- Going round in circles (module 54, Animation)
- Drills in Deathmatch (topic: Animation)
matrix
ideaA table of values with rows and columns, kept as a list of rows, so
grid[row][column]is one value.- Matrices: rows and columns (module 19, More lists)
- A grid as a game board (module 19, More lists)
- Drills in Deathmatch (topic: More lists)
functionmaxReturns the greatest item of a list, and
minreturns the smallest.- max, min, sum and methods versus functions (module 15, Lists)
- Drills in Deathmatch (topic: Lists)
memoization
ideaStoring each answer of a function in a dict, a memo, by its arguments, so that a repeated call looks the answer up instead of working it out again.
- Challenge: an LRU cache (module 61, Hash tables)
- Memoization (module 65, Dynamic programming)
- Drills in Deathmatch (topic: Dynamic programming)
merge sort
ideaSorts by splitting the list in halves, sorting each half the same way and merging the two sorted halves, in O(n log n) time with O(n) extra memory.
- Merge sort (module 60, Sorting algorithms)
- Drills in Deathmatch (topic: Sorting algorithms)
method
ideaA function that belongs to a value and is called after it with a dot, as in
text.find("a").- Searching in a string (module 11, Working with strings)
module
ideaA file of Python code whose functions and values other programs can import, either from the standard library or written by you.
- Importing a module (module 27, Modules)
- A program of several files (module 31, Creating your own modules)
- Drills in Deathmatch (topic: Creating your own modules)
exceptionModuleNotFoundErrorRaised when an
importnames a module that Python can't find, such as a file that doesn't exist.- A program of several files (module 31, Creating your own modules)
- When you need an import (module 38, Objects as attributes)
- Drills in Deathmatch (topic: Objects as attributes)
monotonic stack
ideaA stack whose items stay in order from bottom to top, which finds the next greater value for every item of a list in O(n).
- Traversals and validation (module 62, Trees and heaps)
mutable
ideaA mutable value, such as a list or a dictionary, can change after it's made, and every variable that refers to it sees the change.
- Two names for one list (module 20, References)
- Drills in Deathmatch (topic: References)
mutable default value
ideaA list or dictionary as a parameter's default value is created only once and shared by every call, so use
Noneand create it in the method.- Default parameter values (module 32, More Python features)
- Default values for parameters (module 40, Class attributes)
- Drills in Deathmatch (topic: Class attributes)
N
name mangling
ideaPython's way of hiding a private name by renaming it after its class, so that
self.__songsinPlaylistis reallyself._Playlist__songs.- Private attributes and derived classes (module 42, Access modifiers)
- Drills in Deathmatch (topic: Access modifiers)
__name__
ideaA variable that is
"__main__"in the file Python started and the module's name in an imported module, which is what the main block checks.- The main block, explained (module 31, Creating your own modules)
- Drills in Deathmatch (topic: Creating your own modules)
negative index
ideaAn index below zero, which counts from the end of a string, so
text[-1]is its last character.- Counting from the end (module 11, Working with strings)
- Drills in Deathmatch (topic: Working with strings)
nested conditional
ideaA conditional statement inside the block of another one, where the indentation shows which
elsebelongs to whichif.- Conditions inside conditions (module 8, Combining conditions)
- Drills in Deathmatch (topic: Combining conditions)
nested loop
ideaA loop inside the body of another loop, which runs all its rounds in each round of the outer loop.
- Loops inside loops (module 12, More loops)
- Helper variables in nested loops (module 12, More loops)
- Drills in Deathmatch (topic: More loops)
functionnextAsks an iterator, such as a generator, for its next value, and raises
StopIterationwhen there are no values left.- Iterators (module 43, Object oriented programming techniques)
- next and StopIteration (module 50, Generators)
- Generator expressions (module 50, Generators)
- Drills in Deathmatch (topic: Generators)
method__next__Returns an iterator's next item, and raises
StopIterationwhen there are no items left.- Iterators (module 43, Object oriented programming techniques)
- Drills in Deathmatch (topic: Object oriented programming techniques)
node
ideaOne item of a tree, holding a value and references to its children.
- Binary trees (module 48, More recursion examples)
literalNoneThe value that means "no value", which a function without a
returngives back, and which methods such aslist.sortreturn.- Return or print? (module 14, More functions)
- Sorting: sort and sorted (module 15, Lists)
- Drills in Deathmatch (topic: More functions)
typeNoneTypeThe type of
None, so an error about a'NoneType' objectmeans a value wasNonewhere an object was expected.- None: no object (module 38, Objects as attributes)
- Drills in Deathmatch (topic: Objects as attributes)
keywordnotTurns a condition around, so
not TrueisFalseandnot FalseisTrue.- Turning a condition around: not (module 8, Combining conditions)
- Drills in Deathmatch (topic: Combining conditions)
O
object
ideaA value in the computer's memory with data of its own, such as a list, a string or an object made from a class; in Python every value is an object.
- Everything is an object (module 33, Objects and methods)
- Classes are blueprints (module 33, Objects and methods)
- Drills in Deathmatch (topic: Objects and methods)
object-oriented programming
ideaA way of writing programs around classes and the objects made from them, where each object keeps its data together with the methods that handle it.
- Everything is an object (module 33, Objects and methods)
- Classes are blueprints (module 33, Objects and methods)
functionopenOpens the file with the given name, for reading by default, or for writing with the mode
"w"or appending with"a", and returns a file handle.- Opening and reading a file (module 23, Reading files)
- Creating and writing a file (module 24, Writing files)
- Adding to the end of a file (module 24, Writing files)
- Drills in Deathmatch (topic: Reading files)
operator overloading
ideaGiving a class special methods such as
__lt__or__add__, so that operators like<and+work with its objects.- Comparing objects with operators (module 43, Object oriented programming techniques)
- Drills in Deathmatch (topic: Object oriented programming techniques)
keywordorCombines two conditions into one that is true when at least one of them is true.
- At least one: or (module 8, Combining conditions)
- Drills in Deathmatch (topic: Combining conditions)
functionos.removeDeletes the file with the given name, after
import os.- Clearing, rewriting and deleting files (module 24, Writing files)
- Drills in Deathmatch (topic: Writing files)
overriding
ideaWriting a method in a derived class with the same name as a method of its base class, so that objects of the derived class use the new version.
- Overriding methods (module 41, Class hierarchies)
- Calling the base class with super() (module 41, Class hierarchies)
- Drills in Deathmatch (topic: Class hierarchies)
P
palindrome
ideaA string that reads the same backwards and forwards, such as "racecar".
- Fibonacci, strings and lists (module 47, Recursion)
parameter
ideaA variable named in a function's header, which gets its value from the matching argument of each call.
- Parameters and arguments (module 13, Defining functions)
- Several parameters (module 13, Defining functions)
- Drills in Deathmatch (topic: Defining functions)
PascalCase
ideaThe style for class names, with every word starting with a capital letter and no underscores, as in
BankAccount.- Your first class (module 34, Defining classes)
keywordpassA statement that does nothing, used where Python needs one, such as the body of a function not written yet.
- Your own functions (module 13, Defining functions)
- pass, and loops with else (module 32, More Python features)
prefix sum
ideaA list whose item
iis the sum of the firstivalues, so the sum of any stretchvalues[a:b]isprefix[b] - prefix[a], in O(1).- Prefix sums (module 59, Complexity and searching)
- Drills in Deathmatch (topic: Complexity and searching)
private attribute
ideaAn attribute whose name starts with two underscores, such as
self.__balance, which only the class's own methods use by that name.- Private attributes (module 39, Encapsulation)
- Drills in Deathmatch (topic: Encapsulation)
private method
ideaA helper method whose name starts with two underscores, which the class's own methods call with
self.and the client can't call.- Private methods (module 39, Encapsulation)
- Drills in Deathmatch (topic: Encapsulation)
function@propertyA decorator that turns a method into a getter, so the client reads the value like an attribute, without parentheses.
- Getters with @property (module 39, Encapsulation)
- Setters that check the value (module 39, Encapsulation)
- Drills in Deathmatch (topic: Encapsulation)
protected attribute
ideaAn attribute whose name starts with one underscore, such as
self._songs, which by agreement is for the class and its derived classes but not for clients.- Protected attributes (module 42, Access modifiers)
- Protected methods (module 42, Access modifiers)
- Drills in Deathmatch (topic: Access modifiers)
pruning
ideaStopping a branch of a search as soon as it can't lead to an answer, such as a queen on an attacked square, so whole subtrees of choices are never tried.
- Combinations and pruning (module 64, Recursion and backtracking)
- The N queens (module 64, Recursion and backtracking)
- Drills in Deathmatch (topic: Recursion and backtracking)
pure function
ideaA function whose only result is the value it returns, so it changes none of its arguments and nothing else.
- Side effects (module 20, References)
- Drills in Deathmatch (topic: References)
modulepygameA library for writing games and other programs with graphics, installed with
pip install pygame-ceand taken into use withimport pygame.- A window of your own (module 53, Pygame)
- Drills in Deathmatch (topic: Pygame)
functionpygame.display.flipShows everything drawn in the window so far as one new frame.
- A window of your own (module 53, Pygame)
- Drills in Deathmatch (topic: Pygame)
functionpygame.display.set_captionSets the title in the window's title bar.
- The title and shapes (module 56, More pygame techniques)
- Drills in Deathmatch (topic: More pygame techniques)
functionpygame.display.set_modeOpens a window of the given size, as in
set_mode((320, 240)), and returns it as a surface to draw on.- A window of your own (module 53, Pygame)
- Drills in Deathmatch (topic: Pygame)
modulepygame.drawDraws shapes on a surface with functions such as
rect,circle,lineandpolygon, which take the surface and the color first.- The title and shapes (module 56, More pygame techniques)
- Drills in Deathmatch (topic: More pygame techniques)
functionpygame.event.getReturns a list of the events that have happened since it was last called, such as key presses, mouse clicks and closing the window.
- A window of your own (module 53, Pygame)
- Events and key presses (module 55, Events)
- Drills in Deathmatch (topic: Events)
functionpygame.font.SysFontMakes a font of a named typeface and size, whose
rendermethod makes an image of a text to draw withblit.- Text in the window (module 56, More pygame techniques)
- Drills in Deathmatch (topic: More pygame techniques)
functionpygame.image.loadReads an image file, such as a PNG, and returns it as a surface that can be drawn with
blit.- Images and coordinates (module 53, Pygame)
- Drills in Deathmatch (topic: Pygame)
functionpygame.key.get_pressedTells which keys are held down right now:
keys[pygame.K_LEFT]isTruewhile the left arrow is down.- Keys held down (module 55, Events)
- Drills in Deathmatch (topic: Events)
typepygame.RectA rectangle with a position and a size, with attributes such as
rightandcenterthat follow when it moves.- A small game (module 56, More pygame techniques)
- Drills in Deathmatch (topic: More pygame techniques)
typepygame.time.ClockA clock whose
tick(60), called once in every round of the main loop, keeps the loop from going round more than 60 times a second.- Moving pictures (module 54, Animation)
- Drills in Deathmatch (topic: Animation)
functionpygame.time.get_ticksGives the number of milliseconds since the program called
pygame.init().- Text in the window (module 56, More pygame techniques)
- Drills in Deathmatch (topic: More pygame techniques)
functionpygame.transform.rotateReturns a new image, the given one turned counterclockwise by a number of degrees, made bigger so that its corners fit.
- Going round in circles (module 54, Animation)
- Drills in Deathmatch (topic: Animation)
Q
quantifier
ideaA mark after part of a regular expression, such as
*,+,?or{3}, that says how many times that part repeats.- Repetition and groups (module 52, Regular expressions)
- Drills in Deathmatch (topic: Regular expressions)
quickselect
ideaFinds the k-th smallest value without sorting, by partitioning around a pivot as quicksort does and going on only in the side that holds it: O(n) on average, O(n²) at worst.
- The k smallest and the median (module 60, Sorting algorithms)
- Drills in Deathmatch (topic: Sorting algorithms)
quicksort
ideaSorts by moving the items smaller than a pivot before it and the rest after it, then sorting both sides: O(n log n) on average, O(n²) with bad pivots.
- Quicksort and partitioning (module 60, Sorting algorithms)
- Drills in Deathmatch (topic: Sorting algorithms)
R
keywordraiseRaises an exception on purpose, as in
raise ValueError("bad age"), so that the caller must handle it.- Raising errors yourself (module 25, Handling errors)
- Drills in Deathmatch (topic: Handling errors)
modulerandomMakes pseudorandom numbers and random choices, with functions such as
randint,choice,shuffle,sampleandseed.- Random whole numbers (module 28, Randomness)
- Choosing and shuffling (module 28, Randomness)
- Drawing without repeats, and seeds (module 28, Randomness)
- Drills in Deathmatch (topic: Randomness)
functionrandom.choicePicks one random item of a list, or one character of a string.
- Choosing and shuffling (module 28, Randomness)
- Drills in Deathmatch (topic: Randomness)
functionrandom.randintGives a random whole number between its two arguments, both ends included, so
random.randint(1, 6)rolls a die.- Random whole numbers (module 28, Randomness)
- Drills in Deathmatch (topic: Randomness)
functionrandom.sampleReturns a new list of the given number of different items picked at random, as when drawing lottery numbers.
- Drawing without repeats, and seeds (module 28, Randomness)
- Drills in Deathmatch (topic: Randomness)
functionrandom.seedSets the starting point of the pseudorandom numbers, so that the same seed gives the same numbers on every run.
- Random whole numbers (module 28, Randomness)
- Drawing without repeats, and seeds (module 28, Randomness)
- Drills in Deathmatch (topic: Randomness)
functionrandom.shufflePuts the items of a list in a random order, changing the list itself and returning
None.- Choosing and shuffling (module 28, Randomness)
- Drills in Deathmatch (topic: Randomness)
functionrangeGives the whole numbers from a start up to but not including an end, with an optional step, as in
range(1, 10, 2).- Counting with range (module 16, Definite iteration)
- Ranges, lists and new lists (module 16, Definite iteration)
- Drills in Deathmatch (topic: Definite iteration)
raw string
ideaA string written with an
rbefore its quotes, such asr"\d+", in which Python leaves every backslash as it is.- What regular expressions are (module 52, Regular expressions)
- Drills in Deathmatch (topic: Regular expressions)
modulerePython's module for regular expressions, with functions such as
re.search,re.findall,re.fullmatchandre.sub.- What regular expressions are (module 52, Regular expressions)
- Drills in Deathmatch (topic: Regular expressions)
functionre.findallReturns a list of all the parts of a text that match a pattern, as strings.
- What regular expressions are (module 52, Regular expressions)
- Alternatives and character classes (module 52, Regular expressions)
- Drills in Deathmatch (topic: Regular expressions)
functionre.fullmatchMatches only when the pattern covers the whole text, which makes it the tool for checking a complete value such as an input.
- Repetition and groups (module 52, Regular expressions)
- Checking input and replacing text (module 52, Regular expressions)
- Drills in Deathmatch (topic: Regular expressions)
functionre.searchLooks for the first place in a text that matches a pattern and returns a match object, or
Nonewhen there is no match.- What regular expressions are (module 52, Regular expressions)
- Alternatives and character classes (module 52, Regular expressions)
- Drills in Deathmatch (topic: Regular expressions)
functionre.subReturns a new string in which every part of a text that matches a pattern is replaced with another string.
- Checking input and replacing text (module 52, Regular expressions)
- Drills in Deathmatch (topic: Regular expressions)
methodRect.collidepointTells whether a point, such as the
posof a mouse click, is inside the rectangle.- A small game (module 56, More pygame techniques)
- Drills in Deathmatch (topic: More pygame techniques)
methodRect.colliderectTells whether two rectangles overlap, as in
robot.colliderect(coin); rectangles that only touch side by side don't.- A small game (module 56, More pygame techniques)
- Drills in Deathmatch (topic: More pygame techniques)
recursion
ideaA function calling itself to solve a smaller version of the same problem.
- A function that calls itself (module 47, Recursion)
- Recursion that returns a value (module 47, Recursion)
- Binary trees and recursion (module 62, Trees and heaps)
- Drills in Deathmatch (topic: Recursion)
recursion limit
ideaThe most calls Python lets wait at once, about 1000; past it a
RecursionErrorstops the program, so a deep search uses a loop and a stack of its own.- Depth-first search and flood fill (module 63, Graphs)
- Memoization (module 65, Dynamic programming)
- Drills in Deathmatch (topic: Graphs)
exceptionRecursionErrorRaised when too many calls wait at once, past Python's limit of about 1000: usually a missing base case, or a recursion too deep for its input.
- A function that calls itself (module 47, Recursion)
- Depth-first search and flood fill (module 63, Graphs)
- Drills in Deathmatch (topic: Recursion)
refactoring
ideaRewriting working code to make it clearer or simpler, without changing what it does.
- Pushing boxes (module 57, Game project)
reference
ideaWhat a variable holds for a list or another object, telling Python where the object is, so two variables can refer to one and the same list.
- Two names for one list (module 20, References)
- Lists as parameters (module 20, References)
- Drills in Deathmatch (topic: References)
regular expression
ideaA pattern that describes a kind of text, such as any number or a valid code, used to search, check and replace text.
- What regular expressions are (module 52, Regular expressions)
- Alternatives and character classes (module 52, Regular expressions)
- Drills in Deathmatch (topic: Regular expressions)
functionreprGives the technical text of a value, such as
'Ada'with its quotes for a string.- __str__ and __repr__ (module 43, Object oriented programming techniques)
- Drills in Deathmatch (topic: Object oriented programming techniques)
method__repr__Returns a technical text of an object, often like the code that creates it, which
repr, printed lists and aprintwithout__str__use.- __str__ and __repr__ (module 43, Object oriented programming techniques)
- Drills in Deathmatch (topic: Object oriented programming techniques)
keywordreturnEnds a function and gives a value back to the code that called it, which can store it, print it or use it in a calculation.
- Returning a value (module 14, More functions)
- Return or print? (module 14, More functions)
- Drills in Deathmatch (topic: More functions)
return value
ideaThe value a function gives back to the code that called it, such as the string that
inputreturns.- Functions, arguments and return values (module 6, Programming terminology)
- Drills in Deathmatch (topic: Programming terminology)
RGB
ideaA way to give a color as three numbers from 0 to 255 for its red, green and blue light, such as
(255, 255, 0)for yellow.- A window of your own (module 53, Pygame)
- Drills in Deathmatch (topic: Pygame)
runtime error
ideaAn error that happens while the program runs, such as a division by zero, so the lines before it have already run.
- Errors and debugging (module 6, Programming terminology)
- Drills in Deathmatch (topic: Programming terminology)
exceptionRuntimeErrorThe error Python raises when a dictionary gains or loses keys while a
forloop goes through it.- Removing keys (module 21, Dictionary)
- A map that works like dict (module 61, Hash tables)
- Drills in Deathmatch (topic: Dictionary)
S
scope
ideaThe part of a program where a variable can be used, such as only inside one function for a local variable.
- Local variables (module 26, Local and global variables)
- Drills in Deathmatch (topic: Local and global variables)
self
ideaThe first parameter of every method, the object the method was called on, used to reach its attributes and methods as
self.name.- The constructor and self (module 34, Defining classes)
- Methods in a class (module 35, Defining methods)
- Drills in Deathmatch (topic: Defining methods)
sep
ideaThe keyword argument of
printthat sets what goes between the values, asendsets what goes at the end of the line.- Joining values in print: sep and end (module 17, Print statement formatting)
- Drills in Deathmatch (topic: Print statement formatting)
separation of concerns
ideaDividing a program into parts that each take care of one area of the work, such as the logic, the user interface and the storage.
- Start with the application logic (module 44, Developing a larger application)
- Drills in Deathmatch (topic: Developing a larger application)
typesetA collection that holds each value only once and keeps no order, written
{1, 2, 3}or made withset().- Sets and set comprehensions (module 46, More comprehensions)
- Sets and dicts for speed (module 59, Complexity and searching)
- Drills in Deathmatch (topic: More comprehensions)
set comprehension
ideaBuilds a new set in a single expression, such as
{len(word) for word in words}, so repeated values are kept only once.- Sets and set comprehensions (module 46, More comprehensions)
- Drills in Deathmatch (topic: More comprehensions)
methodset.addAdds a value to a set, and does nothing if the value is already in it.
- Sets and set comprehensions (module 46, More comprehensions)
methodset.updateAdds every item it's given to a set, such as the items of a list, as
adddoes for one item.- A sudoku solver (module 64, Recursion and backtracking)
setter
ideaA method that changes the value of an attribute and can check the new value first, written with
@name.setterafter the getter.- Setters that check the value (module 39, Encapsulation)
- Drills in Deathmatch (topic: Encapsulation)
side effect
ideaA change a function makes outside itself besides returning its value, such as sorting a list it was given.
- Side effects (module 20, References)
- Drills in Deathmatch (topic: References)
single responsibility principle
ideaThe rule that a class should do one kind of work, so there is only one kind of reason to change it.
- Start with the application logic (module 44, Developing a larger application)
- Drills in Deathmatch (topic: Developing a larger application)
slice
ideaA piece of a string, written
text[start:end], with the characters from the indexstartup to but not includingend.- Slices (module 11, Working with strings)
- Drills in Deathmatch (topic: Working with strings)
slice assignment
ideaReplaces part of a list with the items of another list, or all of its items with
items[:] = ..., changing the list itself.- Lists as parameters (module 20, References)
- Drills in Deathmatch (topic: References)
sliding window
ideaA stretch of values in a row that moves along a list, updated with what enters it and what leaves it instead of being worked out again, for O(n) in all.
- Challenge: sliding windows (module 59, Complexity and searching)
- Drills in Deathmatch (topic: Complexity and searching)
slow and fast pointers
ideaTwo pointers that walk a linked list, one node at a time and two at a time: the slow one ends at the middle, and they meet when the list loops.
- Binary trees and recursion (module 62, Trees and heaps)
snake case
ideaPython's style for variable names: small letters, with underscores between the words, as in
first_name.- Variables (module 2, Information from the user)
- Drills in Deathmatch (topic: Information from the user)
Sokoban
ideaA puzzle game in which a worker pushes boxes onto target squares one square at a time, and can't pull them back.
- The game map (module 57, Game project)
- Drills in Deathmatch (topic: Game project)
functionsortedReturns a new sorted list of the items it's given and leaves the original as it was.
- Sorting: sort and sorted (module 15, Lists)
- Strings can't be changed (module 18, More strings and lists)
- Python's sort: keys and stability (module 60, Sorting algorithms)
- Drills in Deathmatch (topic: Lists)
sorted binary tree
ideaA binary tree in which every node's left subtree holds only smaller values and its right subtree only greater ones.
- A sorted binary tree (module 48, More recursion examples)
- Binary search trees (module 62, Trees and heaps)
- Drills in Deathmatch (topic: More recursion examples)
special method
ideaA method whose name starts and ends with two underscores, such as
__init__or__str__, which Python calls by itself when it needs it.- Printing an object with __str__ (module 36, More examples of classes)
stable sort
ideaA sort that keeps items that compare equal in the order they had; Python's
sortandsorted(Timsort) are stable, so you can sort in several passes.- Merge sort (module 60, Sorting algorithms)
- Python's sort: keys and stability (module 60, Sorting algorithms)
- Drills in Deathmatch (topic: Sorting algorithms)
stack
ideaA collection where the item added last comes out first; a list with
appendandpopis one, and it can take the place of deep recursion.- Traversals and validation (module 62, Trees and heaps)
- Depth-first search and flood fill (module 63, Graphs)
- Drills in Deathmatch (topic: Graphs)
starred assignment
ideaAn assignment where the variable with a
*in front gets a list of the items left over, as intitle, length, *sessions = parts.- Reading and saving the data (module 44, Developing a larger application)
- Drills in Deathmatch (topic: Developing a larger application)
state
ideaThe values of an object's attributes at a given moment, which the object's methods can change.
- Methods that change the object (module 35, Defining methods)
- Drills in Deathmatch (topic: Defining methods)
statement
ideaOne complete instruction in a program, such as an assignment, a
printor a wholeifstatement with its block.- Statements and blocks (module 6, Programming terminology)
- Drills in Deathmatch (topic: Programming terminology)
function@staticmethodA decorator for a method that gets neither the object nor the class, a plain function kept in the class it belongs with.
- Class methods and static methods (module 40, Class attributes)
- Drills in Deathmatch (topic: Class attributes)
modulestatisticsCalculates statistics of a list of numbers, such as
statistics.meanandstatistics.median.- Finding the right module (module 30, Data processing)
- Drills in Deathmatch (topic: Data processing)
exceptionStopIterationThe exception that
nextraises when a generator or another iterator has no more values; aforloop ends quietly when it gets one.- Iterators (module 43, Object oriented programming techniques)
- next and StopIteration (module 50, Generators)
- Drills in Deathmatch (topic: Generators)
typestrThe type of strings;
str(...)turns a value, such as a number, into a string.- Numbers and strings (module 3, Variables and f-strings)
- Combining values when printing (module 3, Variables and f-strings)
- Drills in Deathmatch (topic: Variables and f-strings)
methodstr.countReturns how many times a piece of text appears in a string, without overlaps;
list.countcounts an item in a list.- count, index and replace (module 18, More strings and lists)
- Drills in Deathmatch (topic: More strings and lists)
methodstr.findGives the index where a piece of text first appears in a string, or
-1when it isn't in the string at all.- Searching in a string (module 11, Working with strings)
- Drills in Deathmatch (topic: Working with strings)
methodstr.joinJoins a list of strings into one string, with the string it's called on between the pieces, as in
", ".join(words).- split, join and strip (module 18, More strings and lists)
- Drills in Deathmatch (topic: More strings and lists)
methodstr.replaceReturns a new string where every appearance of one piece of text is replaced with another.
- count, index and replace (module 18, More strings and lists)
- Drills in Deathmatch (topic: More strings and lists)
methodstr.rstripReturns a copy of a string without the whitespace at its right end, and
lstripdoes the same at its left end.- Going through a file line by line (module 23, Reading files)
- Drills in Deathmatch (topic: Reading files)
methodstr.splitCuts a string into a list of pieces, at spaces or at the separator you give, as in
"a,b".split(",").- split, join and strip (module 18, More strings and lists)
- Lines with several values (module 23, Reading files)
- Drills in Deathmatch (topic: More strings and lists)
methodstr.stripReturns a copy of a string without the spaces at its start and its end.
- split, join and strip (module 18, More strings and lists)
- Going through a file line by line (module 23, Reading files)
- Drills in Deathmatch (topic: More strings and lists)
methodstr.upperReturns a copy of a string in capital letters, and
str.lowerreturns one in small letters; the original string stays as it is.- The interactive interpreter (module 14, More functions)
- Strings can't be changed (module 18, More strings and lists)
- Drills in Deathmatch (topic: More functions)
method__str__A method that returns a string describing the object, which
print,strand f-strings use to show it.- Printing an object with __str__ (module 36, More examples of classes)
- Values worked out from others (module 36, More examples of classes)
- Drills in Deathmatch (topic: More examples of classes)
subtree
ideaA node of a tree together with everything below it, which is a complete tree of its own.
- Binary trees (module 48, More recursion examples)
functionsumReturns the sum of the numbers in a list, so
sum(numbers) / len(numbers)is their average.- max, min, sum and methods versus functions (module 15, Lists)
- Drills in Deathmatch (topic: Lists)
functionsuperGives the base class's version of a method, as in
super().__init__(name, health)in the constructor of a derived class.- Calling the base class with super() (module 41, Class hierarchies)
- Drills in Deathmatch (topic: Class hierarchies)
methodSurface.blitDraws an image on another surface with its top-left corner at the given point, as in
window.blit(robot, (60, 90)).- Images and coordinates (module 53, Pygame)
- Drills in Deathmatch (topic: Pygame)
methodSurface.fillPaints a whole surface, such as the window, with one color, as in
window.fill((0, 0, 0)).- A window of your own (module 53, Pygame)
- Drills in Deathmatch (topic: Pygame)
methodSurface.get_widthGives the width of a surface, such as an image or the window, in pixels;
get_heightgives its height.- Centering and many images (module 53, Pygame)
- Drills in Deathmatch (topic: Pygame)
swap
ideaExchanging the values of two variables, which takes one line with a tuple,
a, b = b, a.- Tuples without parentheses (module 22, Tuple)
- Drills in Deathmatch (topic: Tuple)
T
test level
ideaA small, easy level made only for testing one part of a game, such as its ending, without playing the whole game every time.
- Finishing the game (module 57, Game project)
tile
ideaA small square picture; tiles drawn side by side in a grid make up a game's map.
- The game map (module 57, Game project)
- Drills in Deathmatch (topic: Game project)
typetimedeltaA length of time, such as the difference of two datetimes, with the attributes
daysandseconds; adding one to a datetime moves it.- Comparing and calculating with dates (module 29, Times and dates)
- Drills in Deathmatch (topic: Times and dates)
topological sort
ideaOrders the vertices of a directed graph so that every edge points forward, as for jobs that wait for others; Kahn's algorithm finds one, or shows there is a cycle.
- Topological sort (module 63, Graphs)
- Drills in Deathmatch (topic: Graphs)
tree traversal
ideaVisiting every node of a tree once: pre-order puts each node before its subtrees, in-order between them (sorted, in a BST) and post-order after them.
- Traversals and validation (module 62, Trees and heaps)
- Drills in Deathmatch (topic: Trees and heaps)
trie
ideaA tree that stores words letter by letter, so that words with the same beginning share nodes, and finding a word or a prefix of m letters takes O(m).
- Challenge: tries (module 62, Trees and heaps)
- Drills in Deathmatch (topic: Trees and heaps)
literalTrueOne of the two Boolean values, the value of a condition that holds; it is written with a capital T.
- True and False (module 5, Conditional statements)
- Drills in Deathmatch (topic: Conditional statements)
keywordtryStarts a block of code that might raise an exception, which the
exceptblocks after it can handle.- Catching errors with try and except (module 25, Handling errors)
- Different kinds of errors (module 25, Handling errors)
- Drills in Deathmatch (topic: Handling errors)
typetupleAn ordered group of values, such as
(3, 7), that you can index and loop over like a list but can't change after it's made.- What a tuple is (module 22, Tuple)
- What tuples are for (module 22, Tuple)
- Tuples without parentheses (module 22, Tuple)
- Drills in Deathmatch (topic: Tuple)
two pointers
ideaTwo indexes that walk along sorted data, each in one direction only, where the order tells which one to move next, so the whole walk is O(n).
- Two pointers (module 59, Complexity and searching)
- Drills in Deathmatch (topic: Complexity and searching)
functiontypeTells the type of a value, such as
int,float,strorbool.- Types of results (module 4, Arithmetic operations)
- True and False (module 5, Conditional statements)
- Drills in Deathmatch (topic: Arithmetic operations)
type hint
ideaA note in a function's first line that tells the types of its parameters and its return value, as in
def area(width: float) -> float:, which Python doesn't check.- Argument types and type hints (module 14, More functions)
- Type hints (module 31, Creating your own modules)
- Drills in Deathmatch (topic: Creating your own modules)
exceptionTypeErrorPython stops with it when an operation gets a value of a type it can't work with, such as a string plus a number.
- Numbers and strings (module 3, Variables and f-strings)
- Combining values when printing (module 3, Variables and f-strings)
- Numbers as input (module 4, Arithmetic operations)
- Drills in Deathmatch (topic: Variables and f-strings)
U
exceptionUnboundLocalErrorRaised when a function reads a local variable before giving it a value, often because it assigns to a global name without
global.- The global keyword (module 26, Local and global variables)
- Drills in Deathmatch (topic: Local and global variables)
union-find
ideaKeeps groups that only ever merge as trees in a list of parents; with union by size and path compression, joining two groups and asking if two items share one take almost O(1).
- Challenge: union-find (module 63, Graphs)
- Drills in Deathmatch (topic: Graphs)
unpacking
ideaPutting the values of a tuple into several variables at once, as in
minutes, seconds = to_minutes(135).- Tuples without parentheses (module 22, Tuple)
- Drills in Deathmatch (topic: Tuple)
user interface
ideaThe part of a program that talks to the user, such as a text interface that reads commands and calls the logic's methods.
- Start with the application logic (module 44, Developing a larger application)
- A text user interface (module 44, Developing a larger application)
- Drills in Deathmatch (topic: Developing a larger application)
V
exceptionValueErrorPython stops with it when a value has the right type but can't be used, such as
int("2.5").- Numbers as input (module 4, Arithmetic operations)
- Checking input before using it (module 25, Handling errors)
- Catching errors with try and except (module 25, Handling errors)
- Drills in Deathmatch (topic: Arithmetic operations)
variable
ideaA name that holds a value, so the program can use the value later and change it.
- Variables (module 2, Information from the user)
- Changing a value (module 3, Variables and f-strings)
- Drills in Deathmatch (topic: Variables and f-strings)
W
keywordwhileStarts a loop, and
while Truerepeats its block until abreakends it.- Repeating with while True (module 9, Simple loops)
- Loops that count (module 9, Simple loops)
- Drills in Deathmatch (topic: Simple loops)
keywordwithwith open(name) as file:keeps a file open while its indented block runs and closes it when the block ends, even after an error.- Opening and reading a file (module 23, Reading files)
- Drills in Deathmatch (topic: Reading files)
Y
keywordyieldHands out one value from a generator function and pauses it there, so that it can continue from the same spot when the next value is asked for.
- Generator functions and yield (module 50, Generators)
- Drills in Deathmatch (topic: Generators)
Z
functionzipGoes through two or more lists side by side, giving tuples of the items at the same place, as in
for w, v in zip(weights, values):.- Challenge: the 0/1 knapsack (module 65, Dynamic programming)
- Drills in Deathmatch (topic: Dynamic programming)