Symbols
* (splat) operator 9-10, 38, 190
**kwargs parameter 153
*args parameter 9-10, 38, 212
% (modulus operator) 205
+ operator 38, 60
< operator 3-4, 136
> operator 3-4
A
abstract base class 187
abstract methods 187
access time (atime) 211
adding numbers 125-127
exercise 126
after integer 13
all_lines function 207, 209, 213
alphabetizing names 40-46
exercise 41-43
anonymous strings 44
array type 36
Arrow package, PyPI 87
associative arrays 53
atime (access time) 211
average method 159
B
b flag 75
before integer 13
binary mode 75
break command 4
BufferedReader object 73
built-in types 55
builtins module 145
builtins namespace 173
bytes mode 75
C
__call__ method 212
callable classes 165
callable value 152
capitalized words 20, 26
ce string 20
chain object 211
child classes 179
chr function 16, 96
Circle class 204-205, 207
solution 206
CircleIterator class 205, 207
class attributes 176
class keyword 161, 163
classes 161-168, 185-189
Circle class 204-207
solution 206
FlexibleDict class 183-185
exercise 183-184
solution 184-185
MyEnumerate class 202-204
exercise 202-203
solution 203-204
code point 27
collections 29
collections module 47, 51, 54
collections.Counter 31
comparison operators 3
comparisons 2
complex type 1
composition 168-175, 189-193
exercises 169-170, 190
comprehensions
adding numbers 125-127
exercise 126
flattening lists 127-129
exercise 128
flipping dicts 131-133
exercise 132
solution 132-133
gematria 137-142
exercises 138, 140-141
joining numbers 118-125
exercise 119-122
solution 122-123
overview 117
Pig Latin translator 129-131
exercise 129-130
supervocalic words 135-137
exercise 136
transforming values 133-135
exercise 134
constant time 55
constants 21, 41
context managers 72, 74, 79, 81
Counter class 47, 183
Counter.most_common 47
create_scoops function 162
creation time (ctime) 211
CSV (comma-separated values), reading and writing 88-91
exercise 90
solution 90-91
csv module 88, 91
csv.reader 90
csv.writer 90
csv.writerow 90
ctime (creation time) 211
current_line 76
D
data attributes
exercise 175-177
solution 177-178
dataclass decorator 172
dataclasses.dataclass 161
date objects 59
Decimal class 13, 144, 149
def function 44
defaultdict 63, 183
default_factory 173
__del__ method 178
dial method 182
dict 56, 160, 183
dict comprehension 72, 117
dictdiff function 64-68
exercise 64-67
dict.fromkeys method 151
dict.get method 56, 60, 62
dictionaries (dicts)
dictdiff function 64-68
exercise 64-67
hashing and 54-55
number of different integers 68-70
exercise 69
solution 69-70
rainfall tracker 59-64
restaurant menu 57-59
exercise 57-58
sets 56
dict.items method 56, 93, 132
dict.keys() method 65, 151
dict_partition function 68
dict.setdefault 93
dict.update method 68
digit variable 14
dispatch table 153
distribution package 156
DRY (don’t repeat yourself) 19, 143, 179-180
E
elapsed_since function 211
end of lines 89
__enter__ method 81
enumerate function 2, 14, 118, 201-202, 204
enumerate iterator 138
Envelope class 182
eval function 3
even_odd_sums function 35
except OSError clause 208
__exit__ method 81
expressions 125
F
field separators 23
filename variable 85
files
JSON 91-95
exercise 92-94
longest word per file 85-88
exercise 85-86
password file reader 78-81
exercise 79
solution 79-80
reading and writing CSV 88-91
exercise 90
solution 90-91
retrieving final line 73-77
exercise 73-76
solution 76-77
reversing lines 95-97
exercise 95-96
word counter 81-84
exercise 82-84
file_usage_timing function 211
filter function 123-124
final_line 76
find_all_longest_words function 85
find_longest_word function 85
firstlast function 31-37
exercise 31-35
FlatList class 185
flatten function 128
flattening lists 127-129
exercise 128
flatten_odd_ints function 128
flavor attribute 163
FlexibleDict class 183, 185
exercise 183-184
solution 184-185
flipping dicts 131-133
exercise 132
solution 132-133
float type 1, 13
floating-point numbers 12
floating-point values 11
foo function 165
for loops 2
format_sort_records function 49
freedonia.py module 148
from X import Y 144
f-strings 2, 4, 7-8, 12, 50, 126
funcfile function 131
functional programming
adding numbers 125-127
exercise 126
flattening lists 127-129
exercise 128
flipping dicts 131-133
exercise 132
solution 132-133
gematria 137-142
exercises 138, 140-141
joining numbers 118-125
exercise 119-122
solution 122-123
Pig Latin translator 129-131
exercise 129-130
supervocalic words 135-137
exercise 136
transforming values 133-135
exercise 134
functions
password-generation function 111-114
solution 113-114
prefix notation calculator 107-111
exercise 108-110
XML generator 101-107
exercise 102-103
G
garbage collection 178
gematria 137-142
exercises 138, 140-141
gematria_equal_words function 140
gematria_for function 139
generator expressions 122, 170, 197
generator functions 197, 200
generators 197
iterator for all lines, all files 207-209
exercise 207-208
mychain generator function 211-214
exercise 212
time elapsed since last iteration 209-211
exercise 210
get_final_line function 73
__getitem__ method 183-184
get_nutrition method 182
get_rainfall function 59
get_sv function 135
glob method 88, 92
global frame 6
globbing 87
glob.glob function 72, 87, 133, 135
H
“has-a” rule 170
hash function 55
hash maps 53
hash marks 8
hash tables 53
hashable types 54-55
hashes 53
hashlib module 72, 86
hexadecimal output 14-16
exercise 14-15
hex_output function 14
I
ICPO rule 177, 180
if clause 128, 140
if statement 11, 60
immutable strings 17
immutable structures 21
import function 144-145, 151, 155
import MODULENAME variable 146
importlib module 152
importlib.reload 144
in operator 17-19, 30-31, 57
IndexError exception 79
inheritance 180-183
exercise 180-181
solution 181-182
__init__ method 161, 163, 165-167, 175, 186, 202, 205, 207
__init__.py file 156
input errors 61
input function 2-4, 11, 56, 118
int class 15
int function 6, 14, 16
int type 1
io.StringIO 35
“is-a” rule 170
isdecimal method 62
isdigit method 62
isnumeric method 62
itemgetter function 42-43, 46
items method 50
items tuple 38
iter function 185
__iter__ method 198, 200, 204-205, 212
iter method 201
iterables 200-201
iterators
Circle class 204-207
solution 206
iterator for all lines, all files 207-209
exercise 207-208
mychain generator function 211-214
exercise 212
MyEnumerate class 202-204
exercise 202-203
solution 203-204
time elapsed since last iteration 209-211
exercise 210
itertools module 200-201, 211
itertools.chain function 213
J
joining numbers 118-125
exercise 119-122
solution 122-123
join_numbers function 119
JSON (JavaScript object notation) 71
exercise 92-94
json module 91-92, 94
json.load method 91, 93
K
d 56
key argument 184
key parameter 42, 47
keys 53
key-value pairs 53, 55, 62, 127, 152
L
lambda function 42, 44-46
len function 42, 94
lines, end of 89
list comprehensions 30, 117
list.append function 18, 23, 36
list.remove method 36
lists
alphabetizing names 40-46
exercise 41-43
lists (continued)
firstlast function 31-37
exercise 31-35
flattening lists 127-129
exercise 128
printing tuple records 49-52
exercise 50-51
summing anything 37-40
solution 39-40
useful references 30-31
word with most repeated letters 46-49
exercise 47-48
loading modules 151
LogFile class 165
longest word per file 85-88
exercise 85-86
M
map function 123-124, 133
mappings 55
max function 31, 94
menu function 153
menu.py file 152, 155
exercise 153-154
restaurant menu 57-59
exercise 57-58
min function 93
mm function 146
modification time (mtime) 211
modules 155
exercise 153-154
sales tax calculator 147-152
exercise 148-150
modulus operator (%) 205
most_common method 47
most_repeating_letter_count function 48
most_repeating_word function 46
multiprocessing module 154
mutable structures 21
mychain generator function 211-214
exercise 212
MyEnumerate class 202, 204
exercise 202-203
solution 203-204
MyEnumerateIterator class 203-204
mylist function 42, 44
mymod function 146
MyRange class 207, 213
mysum function 8-9, 38-39
mysum_bigger_than function 40
N
__name__ variable 153
name-value pairs 53
nested list comprehensions 121, 131
__new__ method 165-166, 168
newline character 74, 82, 89
__next__ method 198, 200, 202, 204-205, 207, 212
next method 201
Novel class 179
number_of_vowels function 120
numbers
adding 125-127
exercise 126
joining 118-125
exercise 119-122
solution 122-123
number guessing game 2-8
solution 6
number of different integers 68-70
exercise 69
solution 69-70
summing 8-10
exercise 9-10
solution 10
numbers argument 9
numbers function 9
numeric types
hexadecimal output 14-16
exercise 14-15
numeric types (continued)
number guessing game 2-8
solution 6
run timing 11-13
exercise 11-12
summing numbers 8-10
exercise 9-10
solution 10
useful references 2
NumPy 36, 146
O
object class 36
object-oriented programming 158
objects
classes 161-168, 185-189
combining techniques 193-196
exercise 194
solution 194-195
composition 168-175, 189-193
exercises 169-170, 190
exercise 175-177
solution 177-178
FlexibleDict class 183-185
exercise 183-184
solution 184-185
inheritance 180-183
exercise 180-181
solution 181-182
one-character string 17
one_line.split 82
open function 73
operator module 42
ord function 16, 96, 132
os module 145, 147
os.listdir function 70, 72, 87, 92, 133, 135, 201, 207, 209
os.path.join function 86-87, 201, 207
os.path.splitext 70
os.py function 145
os.pyc function 145
os.sep function 146, 207
os.stat function 72, 84, 87, 95
os.walk function 201, 207
output variable 9
P
packages
exercise 153-154
parent class 179
pass keyword 208
passwd file 90
passwd_to_csv function 89
passwd_to_dict function 78
password file reader 78-81
exercise 79
solution 79-80
password-generation function 111-114
solution 113-114
Path object 87
pathlib module 87
Person class 116, 178
person_dict_to_list function 42
Phone class 182
Pig Latin
sentences 22-24
exercise 22-23
solution 23
translator 129-131
exercise 129-130
solution 20
pip 144
pl_sentence function 22
plus_minus function 36
plword function 129, 131
PosixPath object 88
power variable 14
prefix notation calculator 107-111
exercise 108-110
printf 7
printing tuple records 49-52
exercise 50-51
print_scores function 91
procedural programming 158
punctuation 21
PyPI (Python Package Index) 145, 155-156
Python property 164
Python Tutor 6
Pythonic code 12
PYTHONPATH variable 151
R
r+ mode 96
rainfall tracker 59-64
randint function 3
random module 2-4
range class 30, 207, 213
range function 119, 201
raw_input function 3
re module 209
read method 75
RecentDict class 185
redundancy, reducing 172
reload function 152
reloading modules 151
__repr__ method 161, 170, 189
re.split function 23
restaurant menu 57-59
exercise 57-58
result variable 93
result.items() method 93
retrieving final line 73-77
exercise 73-76
solution 76-77
return statement 209
return_value function 153
reversed function 14-15
reversing lines 95-97
exercise 95-96
run timing 11-13
exercise 11-12
run_app method 182
run_func_with_world function 45
S
sales tax calculator 147-152
exercise 148-150
Scoop class 162, 164, 168
ScoreList 159
self parameter 163, 166
self.index attribute 202-203, 205
sep function 146
sequences 30, 198
set.add 56, 69
sets
dictdiff function 64-68
exercise 64-67
number of different integers 68-70
exercise 69
solution 69-70
set.update 56, 69, 72
setup.py file 156
Shelf class 171
shell 49, 97
sorted function 18, 26, 28, 41-43, 48, 50, 121
sorting strings 26-28
exercise 26-27
solution 27
space_required attribute 193
splat (*) operator 9-10, 38, 190
split 83
standard library 144-145
StopIteration exception 198, 200-201, 204, 209
str function 30, 120, 160
__str__ method 170
str.endswith method 78
str.format method 7-8, 31, 50
string indexes 32
string literals 44
string module 138
string.ascii_lowercase 118
string.ascii_lowercase attribute 138
StringIO 21, 77, 137
strings
Pig Latin sentences 22-24
exercise 22-23
solution 23
solution 20
sorting strings 26-28
exercise 26-27
solution 27
Ubbi Dubbi 24-26
exercise 25
useful references 18
str.isalpha function 151
str.isdigit method 6, 56, 62, 118, 126, 151
str.isspace function 151
str.join function 18, 23, 27-28, 118-119, 130, 153, 170, 207
str.replace function 25
str.rstrip() method 79, 96
strsort function 26
str.split method 18, 22-23, 28, 52, 72, 79, 118, 126
str.startswith method 78-79, 90
str.strip method 78
subclasses 179
subject_scores 93
sum function 8, 10, 94, 120, 122
summing
anything 37-40
solution 39-40
numbers 8-10
exercise 9-10
solution 10
sum_numbers function 125
sum_numeric function 40
super built-in 161
supervocalic words 135-137
exercise 136
sys.getsizeof 36
sys.modules function 152
sys.path function 145, 151
T
TextIOWrapper object 73
this object 163
time elapsed since last iteration 209-211
exercise 210
time_percentage function 148
time.perf_counter 201, 210
transforming values 119, 133-135
exercise 134
transform_values function 133-135
tuples
alphabetizing names 40-46
exercise 41-43
firstlast function 31-37
exercise 31-35
printing tuple records 49-52
exercise 50-51
summing anything 37-40
solution 39-40
useful references 30-31
word with most repeated letters 46-49
exercise 47-48
TypeError exception 4, 9
U
Ubbi Dubbi 24-26
exercise 25
unhashable types 55
Unicode 17, 27, 75
unique_words.update 83
un_timing function 11
upper attribute 173
URL-encode characters 26
V
ValueError exception 6, 150, 184
variable-length encoding 27
W
wc function 81
while loops 2, 5, 61
width attribute 171
with statement 71-72, 74, 80-81, 90, 95
wordcount function 81
words and text
alphabetizing names 40-46
exercise 41-43
Pig Latin sentences 22-24
exercise 22-23
solution 23
Pig Latin translator 129-131
exercise 129-130
solution 20
reversing lines 95-97
exercise 95-96
Ubbi Dubbi 24-26
exercise 25
word counter 81-84
exercise 82-84
word with most repeated letters 46-49
exercise 47-48
X
XML generator 101-107
exercise 102-103
Y
yield statement 200-201
Z
zip function 36, 201, 213