Size: Both · Mini · Full
add Sum up lists-of-lists of numbers
comprehensionslooping
Circle Class representing a Circle, with auto-updating attributes
classespropertiesmath
count_words Count occurrences of each word in a string
regular expressionsdictionariesloopingfunction
tail Return last N items in a given iterable
iteration toollistloopingfunctionslicing
parse_ranges Parse comma-delimited numeric ranges
regular expressionscomprehensionsgeneratorstext processingmaking iterators
dollars Script to display a number as US currency
command line interfaces
to_percent Convert a ratio to a percentage
mathfunction
last_n_elements Get the last N items in a list
listconditionalsfunctionslicing
zero Command-line program that prints eighty 0's
loopingargument parsingcommand line interfaces
swap_ends Swap first and last items in a list
listfunction
split_in_half Split a list into two halves
listfunctionslicing
combine_lists Combine two lists into one
listloopingfunction
head Get the first N items from any iterable
iteration toolcomprehensionslistgeneratorsmaking iteratorsloopingfunction
characters Get a list of lowercased characters from a string
listsortingfunction
line_numbers Program to print lines from a file with their line numbers
loopingcommand line interfacesfunction
reverse_words Reverse words in the given string
listfunctionslicing
flip_dict Flip keys and values in a dictionary.
dictionarieslooping
Point Class representing a 3-dimensional point
classesdataclassesgeneratorsdunder methodsmaking iterators
has_duplicates Determine whether a list has duplicate items
listloopingslicing
jot Script for quickly jotting down ideas for later
command line interfacesfile navigation
len_or_none Return return the length or None (if no length)
exception handlingfunction
is_anagram Determine whether the given words are anagrams
dictionariestext processingunicodefunction
total_air_travel Add up all air travel expenses in a CSV file
csvfile processingargument parsingcommand line interfaces
lucas Generate numbers from the Lucas sequence in your terminal
text processingcommand line interfaces
transpose Transpose a given list-of-lists
comprehensionslistloopingfunction
fix_csv.py Convert pipe-delimited files to comma-delimited files
csvlistfile processingargument parsingcommand line interfaces
matrix_from_string Turn a string into a list-of-lists of numbers
comprehensionsmathlistloopingfunction
rotate_list Rotate item from one end of a list to the other
listconditionals
dict_from_tuple Turn list-of-tuples into a multi-valued dictionary
dictionariesloopingfunction
NextDate Find date of the next given weekday
classesdataclasses
roll Simulate dice rolls.
mathargument parsingcommand line interfaces
fix_newlines Enforce final newlines and normalize file line endings
text processingloopingfile processingcommand line interfacesconditionals
meetup_date Find N-th occurrence of a specific weekday in the month
comprehensionsfunction
is_perfect_square Determine whether a number is a perfect square
math
sort_dict Sort a dictionary by its keys
dictionariessortinglooping
call_later Create a function to call another function at a later time
rock paper scissors Implement the game rock-paper-scissors
dictionariesargument parsingcommand line interfacesconditionals
input_number Prompt a user to enter a number
exception handling
ProxyDict Immutable dictionary-like wrapper around a dictionary
classesmaking iterators
to_jsonl Convert a JSON array file to a JSONL file
file processingcommand line interfaces
uniques_only Get unique items from an iterable while maintaining item order
iteration toollistgeneratorsmaking iteratorsloopingfunctionslicing
print_call_time Decorator to the print time a function took to run
decorators
mask keys Mask sensitive dictionary keys
dictionariesrecursion
duplicates_only Refactor duplicate-checking function to improve performance
dictionariesefficiency
jsonify Decorator to JSON-encode a function's return value
decorators
deep_add Deeply sum numbers in an iterable-of-iterables
recursionlooping
strip_lines Get all lines from a file with newlines removed
iteration toolcomprehensionsgeneratorsmaking iteratorsloopingfile processingfunction
four Repeatedly count the letters within a number
mathtext processingloopingcommand line interfacesconditionals
float_range range-like utility for floating point numbers
classesiteration toolmathgeneratorsdunder methodsloopingefficiency
groot A decorator that always prints "Groot"
decorators
sum_timestamps Sum up a list of MM:SS timestamp strings
regular expressionscomprehensionsgenerators
get_shared_keys Find the common keys between two dictionaries
dictionariesfunction
csv_columns Turn CSV rows into a dictionary mapping headers to columns
dictionariescomprehensionslistloopingfile processing
first Get the first item from any iterable
BankAccount Class representing a bank account with read-only balance
classesproperties
only_once Decorator that only allows functions to be called once
decorators
paste_code A function to help paste code into the Python REPL
loopingexception handlingfunction
format_ranges Format list of numbers into groups of start-stop strings
comprehensionslistgeneratorstext processingsortinglooping
flatten_dict Flatten a dictionary-of-dictionaries
dictionariescomprehensionsrecursionlooping
sort Sort the lines in a file
text processingsortingfile processingcommand line interfaces
window Get each iterable item and the next N-1 items
iteration toolgeneratorsdunder methodsmaking iteratorslooping
Row Class that accepts any given keyword arguments
classes
suppress Context manager that suppresses specific exceptions
classescontext managersdataclassesdecoratorsgeneratorsexception handling
is_iterator Determine whether an iterable is an iterator
chunked Break an iterable into N-length chunks
iteration toolcomprehensionsgeneratorsmaking iteratorsloopingslicing
EasyDict Dictionary-like class supporting both attribute and key lookups
classes
interleave Interleave items from each of the given iterables
iteration toolcomprehensionslistgeneratorsmaking iteratorslooping
dramatic print Print text character-by-character
reformat_diary.py Program to reformat a diary file into multiple files
regular expressionscomprehensionsgeneratorstext processingcommand line interfacesfile navigation
PhoneNumber Class representing a US phone number
classesregular expressions
format_fixed_width Format rows into a string of fixed-width columns
comprehensionslistgeneratorstext processingternary operator
OrderedSet Set-like object that maintains insertion-order of items
classesgeneratorsdunder methodsmaking iteratorsefficiency
tags_equal Determine whether two HTML tags are equivalent
regular expressionscomprehensionstext processingternary operatorslicing
Month Class representing a month and year
classespropertiesdataclassesslotsdunder methodsefficiency
minmax Return both minimum and maximum values in an iterable
dataclassesloopingternary operator
count_calls Decorator that counts the calls to a function
classespropertiesdecorators
maybe An object that is randomly truthy or falsey
classesdunder methods
remove_empty Remove all empty directories recursively
command line interfaces
CyclicList List-like class that loops in a cyclic manner
classesiterable classgeneratorsmaking iterators
deep_flatten Flatten deeply nested iterable-of-iterables
iteration toolrecursiongeneratorsmaking iteratorslooping
print_call_info Create a decorator that prints function call info
decorators
all_same Determine whether all items in an iterable are the same
generatorsloopingfunction
MaxCounter A Counter that can identify all most common keys
classes
Vector Class representing 3-dimensional vector
classesdataclassesslotsgeneratorsdunder methodsmaking iteratorsefficiency
pluck Tool to deeply query a dictionary of dictionaries
dictionariesrecursiontext processingexception handling
fixed2csv.py Convert fixed-width file to CSV file
csvcomprehensionslistgeneratorsloopingfile processingargument parsingcommand line interfacesslicing
float_range (part 2) range-like utility for floating point numbers
classesiterable classiteration toolmathdunder methodsloopingefficiencyslicing
window (part 2) Get each iterable item and the next N-1 items
iteration toolcomprehensionsgeneratorsmaking iteratorsloopingslicing
count_lines Calculate line count for all .py files in a directory
classesdataclassestext processingexception handlingfile navigation
alias A helper that (magically?) alias one attribute to another
classespropertiesdataclassesdescriptors
total_length Find the number of items in all given iterables
comprehensionsgeneratorslooping
PermaDict Dictionary-like objects which don't allow key updates
classesdunder methodsmaking iterators
sort_by_column.py Program to sort a CSV file by specific columns
csvcomprehensionssortingfile processingargument parsingexception handlingcommand line interfaces
FuzzyString String-like class supporting case-insensitive comparisons
classestext processingunicode
minmax (part 2) Getting minimum and maximum values from an iterable (again)
dataclassescomprehensionsloopingternary operatorexception handling
ReverseView A sequence-like class representing the reverse of a given sequence
classesmaking iterators
Count votes Program to count votes for numerical options
regular expressionsdictionariestext processingcommand line interfaces
Timer Context manager to time blocks of code
classescontext managersdecorators
my_builtins Re-implement some built-in functions to learn how they work
generatorsloopingternary operatorexception handling
loop_helper A utility to get helpful information while looping
comprehensionsgeneratorslooping
RandomLooper Loop over iterable items in a random order
classesiterable classcomprehensionslistgeneratorsdunder methods
divide Divide an iterable into N parts
iteration toolcomprehensionsgeneratorsmaking iteratorsslicing
Unpacker Class supporting tuple unpacking of all attributes
classesiterable classdictionariesdunder methods
grades Convert percentages to US-style grades and calculate GPAs
dictionariesmathternary operatorconditionalsfunction
SequenceZip A fancy version of zip just for sequences
classescomprehensionsgeneratorsdunder methods
ini2csv.py Program to convert INI file to a CSV file
regular expressionscsvtext processingfile processingargument parsingcommand line interfacesslicing
Comparator Object to facilitate "almost equal" numerical comparisons
classescontext managersmath
cd Context manager for temporarily changing directories
classescontext managersdataclasses
markdownify Convert basic HTML to basic markdown
regular expressionstext processing
running_mean Utility to calculate a running mean while looping
mathgeneratorsloopingfunction
FancyReader CSV reader that returns friendly objects for each row
classesiterable classdictionariescsvmaking iteratorsfile processing
condense_csv Condense CSV text, to use fewer rows and more columns
dictionariescsvcomprehensionstext processingfile processing
Grouper Dict-like class which groups things using a key function
classesdunder methods
int_to_roman Convert integers to Roman numerals and back
text processingexception handling
MutableString String-like object that is mutable
classescontext managersdunder methodstext processing
strict_zip Like zip, but raises an error for iterables of different lengths
iteration toolcomprehensionsgeneratorsmaking iteratorsexception handling
make_file Context manager to create a temporary file
classescontext managers
normalize_sentences Make sure sentences have two spaces between them
regular expressionstext processingloopingslicing
PiecewiseRange Lazy iterable representing the concatenation of many ranges
classescomprehensionsgeneratorsdunder methodsternary operator
natural_sort Sort strings case-insensitively and numerically
regular expressionscomprehensionstext processingsortingternary operator
MonthDelta MonthDelta class that works along with Month class
classesdataclassesdunder methods
Timer (redux) Reusable context manager to time code blocks, including splitting
classescontext managersdunder methodsconstructor
ages Utilities related to working with birthdates and ages
text processing
record_calls Decorator that records calls to a function
classesdataclassesdecorators
last_lines Get the lines in a file in reverse order
regular expressionslisttext processingmaking iteratorsfile processingbinary filesslicing
FancyReader (redux) A memory-efficient version of csv.DictReader
classespropertiesslotsefficiency
loop_tracker An iterator with extra bells and whistles
propertiesiteration toolmaking iteratorsexception handling
format_bytes Format numbers into human-readable byte sizes
regular expressionsmathtext processingloopingternary operatorslicing
nostar A module that disallows * imports
cached_property Like the property decorator but values are cached
classespropertiesdecoratorsdescriptors
fancy_input Like the built-in input function, but fancier
loopingcommand line interfaces
SliceView A "view" into a sequence, like a lazy slice
iterable classmathrecursiongeneratorsmaking iterators
update_reviews Update one CSV file based on another CSV file
csvcomprehensionsfile processingargument parsingcommand line interfaces
ChainSequence Class to link sequences together
classes
min_n Get the smallest n items in an iterable
listsortingslicing
final_class Making classes which cannot be subclassed.
decoratorsmetaclassesconstructor
concat_check.py Find implicit string concatenation in Python files
regular expressionsfile processingbinary filescommand line interfaces
ProxyDict (redux) Immutable dictionary-like wrapper around a dictionary
classesmaking iterators
file_looper Utility to open many files one after the other
comprehensionsgeneratorsmaking iteratorsfile processing
grep A utility like the Linux/Unix grep command
regular expressionsmathtext processingloopingargument parsingcommand line interfaces
RomanNumeral Class representing a Roman numeral
classesdunder methods
coalesce "Coalesce" a NULL value to a specific default value
decoratorscomprehensionsternary operator
computed_property Cached decorator that recomputes on specific attribute changes
classespropertiesdecoratorscomprehensionsdescriptors
easyjson Convert a JSON string to a JavaScript-like object
classescomprehensionsrecursion
find_duplicates Identifies duplicate files
file processingbinary filesefficiency
Check-writing helper Program to help write the amount/date for a cheque
mathtext processingcommand line interfacesconditionals
MinHeap A heap data structure
classesslotsefficiency
pattern_rename.py Program to rename files from one naming scheme to a different naming scheme
regular expressionscommand line interfaces
validators A descriptor that can only be assigned positive numbers
classesdescriptorsdunder methodsconstructorweak references
smoosh Weirdly-named utilities to flatten iterable of iterables
regular expressionsrecursion
iconv.py Convert text from one character encoding to another
unicodefile processingbinary filesargument parsingcommand line interfaces
instance_tracker Class factory which allows classes to track instances of themselves
constructorweak references
bullet points Utilities for parsing nested bullet points
classesdataclassesregular expressionscomprehensionsdunder methodstext processing
phonetic.py Program to spell words using the NATO phonetic alphabet
dictionariestext processingunicodeargument parsingcommand line interfaces
moviestats Utilities for asking questions of a JSON-based data file
dictionariescomprehensionslistsortingefficiency
SSH log parser Functions to extract data from a compressed SSH log file
dataclassesregular expressions
random_rename Program to to randomize filenames for blinded reviews
csvfile processingargument parsingcommand line interfaces
partial Utility to partially evaluate functions
classesdecoratorscomprehensionsgenerators
Version tests Tests for a Version class which represents a program version
classesdunder methodsexception handlingcommand line interfaces
easyclass A handy custom extension of the dataclass decorator
classesdataclassesiterable classdecorators
dmath Command-line utility for doing date math
exception handlingcommand line interfaces
FieldTracker Class that tracks which attributes have changed
classesdictionariescomprehensions
debug_calls Decorator that prints debug information for the called function
decoratorsintrospection
passphrase Command-line program that randomly generates 4-word passphrases
argument parsingcommand line interfaces
QueryList List-like class with methods for quick queries
classesiterable class
annual_return Calculate financial return rate over many years
regular expressionstext processingcommand line interfaces
plan_meeting Command-line program to help plan international meetings
regular expressionsfile processingargument parsingcommand line interfaces
my_builtins (redux) Re-implement some built-in functions to learn how they work
classesgeneratorsloopingconstructorexception handling
page Command-line tool for paginating text files by their lines
file processingargument parsingcommand line interfaces
reprtools Utilities to help implement __repr__ methods
decoratorscomprehensionsintrospection
SequenceZip (part 2) Like zip-like utility that can be looped over multiple times
classesgeneratorsdunder methods
positional_only Decorator requiring all arguments be positional-only arguments
classespropertiesdecoratorsconstructor
Circle (redux) Class representing a Circle, with auto-updating attributes
classespropertiescomprehensionsmathefficiency
checksum Program to validate file checksums
file processingbinary filescommand line interfaces
iospy Utilities to merge file streams and spy on I/O
classescontext managersproperties
EasyDict (part 2) Dictionary-like class supporting both attribute and key lookups
classes
countdown Command-line visual countdown timer
comprehensionscommand line interfaces
fancy_map Like the built-in map function but can be looped over many times
classesiteration tooldunder methodsmaking iterators
crossword helper Command line util to generate crossword matches based on pattern
regular expressionsargument parsingcommand line interfaces
Tree Tree-like data structure that automatically spawns new branches
classesdictionariesrecursiondunder methods
bind Like functools.partial, but with placeholder arguments
dunder methods
fixed2csv2.py Program to convert fixed-width files to CSV files
regular expressionscsvcomprehensionslistloopingfile processingcommand line interfacesslicing
easyjson (redux) Convert a JSON string to a JavaScript-like object
classesslots
diff_cols Program to compare specific columns in CSV files
csvargument parsingcommand line interfaces
ratelimit Decorator to rate-limit calls to a function
classesdecorators
zipit A CLI for making ZIP files from Python programs
binary filescommand line interfaces
coalesce_args Decorator to "coalesce" arguments to their default values
decoratorsintrospection
HistoryDict Dictionary-like structure that tracks previous item values
classes
tee.py Command-line program to pipe standard input into given files
regular expressionscomprehensionstext processingbinary filesargument parsingcommand line interfacesfile navigation
track_instances Track all instances of the decorated classes
classesslotsmetaclassesgeneratorsdunder methodsconstructorweak references
peekable Iterator that can peek at the next item without consuming it
classesiteration tooldunder methodsmaking iteratorsexception handling
OrderedSet (redux) Set-like object that maintains insertion-order of items
classesmaking iteratorsefficiency
make_class Class factory function
classesefficiency
lines2.py Command-line program to calculate line counts by file type
dataclassescomprehensionsgeneratorstext processingternary operatorargument parsingcommand line interfacesfile navigation
snake_case Utilities to allow "snake_case" usage in a class with "camelCase" methods
classesregular expressionsdecorators
sqlite ORM Lightweight SQLite database orm
classes
dups.py Command-line utility for identifying duplicate files
file processingbinary filesargument parsingefficiencycommand line interfaces
class_property A combination of property decorator and classmethod decorator
classesdecoratorsdescriptors
gz Command-line program compresses (gzips) a given file
file processingbinary filesargument parsingcommand line interfaces
Vector (redux) Class representing 3-dimensional vector
classesdataclassesslotsmaking iteratorsefficiency
SuperMap Class that stores objects based on specific attribute values
classesdunder methods
split Command line program to split a file into smaller files
comprehensionsgeneratorstext processingargument parsingcommand line interfaces
OrderedDict Like collections.OrderedDict but with indexable keys
classesslotsgeneratorsdunder methodsmaking iterators
reloopable Reset iterator each time looping over a file
classescontext managersmaking iteratorsfile processingfile navigation
fancy_iterable A utility that lazily performs various operations on a given iterable
iterable class
warningutils Raise exceptions when warnings are issued
classescontext managersdataclassesgeneratorsdunder methodsexception handling
dunder_all Utilities to help populate a modules' __all__ attribute
context managersintrospection
bullet points (redux) Utilities for parsing nested bullet points along with notes
classesdataclassesregular expressionscomprehensionsdunder methodstext processing
mutable_hash Function to hash common mutable types
slotsrecursionlist
replr A Python REPL that can save and restore its session state
binary filescommand line interfaces
pattern_rename2.py Program to rename files from one naming scheme to a different naming scheme
regular expressionsargument parsingcommand line interfaces
RandomNumber A class attribute that generates new data on each access
classespropertiesdescriptorsmathdunder methods
HistoryDict (redux) Dictionary-like structure that tracks previous item values
classes
overload Decorator for function overloading (based on argument number and types)
classesdecoratorsgeneratorsexception handling
at A utility for chaining decorator functions together
decoratorsmetaclasses
fancy_enums A series of custom enumeration classes
iterable classmetaclasses

Track your progress

Sign Up Now or Log in to track which exercises you've solved, get personalized recommendations, and access exercise paths.