Skip to content

Commit 4074700

Browse files
committed
Merge branch 'dabeaz-course:master' into master
2 parents ac77a7e + 92a8a73 commit 4074700

46 files changed

Lines changed: 706 additions & 153 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

LICENSE.md

Lines changed: 175 additions & 0 deletions
Large diffs are not rendered by default.

Notes/00_Setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ exercises. Feel free to look at this if you need a hint. To get the
8686
most out of the course however, you should try to create your own
8787
solutions first.
8888

89-
[Contents](Contents.md)
89+
[Contents](Contents.md) \| [Next (1 Introduction to Python)](01_Introduction/00_Overview.md)
9090

9191

9292

Notes/01_Introduction/00_Overview.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[Contents](../Contents.md) \| [Next (2 Working With Data)](../02_Working_with_data/00_Overview.md)
2+
13
## 1. Introduction to Python
24

35
The goal of this first section is to introduce some Python basics from
@@ -13,5 +15,4 @@ reads a CSV data file and performs a simple calculation.
1315
* [1.6 Files](06_Files.md)
1416
* [1.7 Functions](07_Functions.md)
1517

16-
[Contents](../Contents.md)
17-
18+
[Contents](../Contents.md) \| [Next (2 Working With Data)](../02_Working_with_data/00_Overview.md)

Notes/01_Introduction/01_Python.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ you accessed is actually feeding the website
169169
<http://ctabustracker.com/bustime/home.jsp>. Try it again and watch
170170
the predictions change.
171171

172+
Note: This service only reports arrival times within the next 30 minutes.
173+
If you're in a different timezone and it happens to be 3am in Chicago, you
174+
might not get any output. You use the tracker link above to double check.
175+
172176
If the first import statement `import urllib.request` fails, you’re
173177
probably using Python 2. For this course, you need to make sure you’re
174178
using Python 3.6 or newer. Go to <https://www.python.org> to download

Notes/01_Introduction/02_Hello_world.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ interact with the interpreter.
5858
Let's take a closer look at the elements of the REPL:
5959

6060
- `>>>` is the interpreter prompt for starting a new statement.
61-
- `...` is the interpreter prompt for continuing a statements. Enter a blank line to finish typing and run the statements.
61+
- `...` is the interpreter prompt for continuing a statement. Enter a blank line to finish typing and run what you've entered.
6262

6363
The `...` prompt may or may not be shown depending on your environment. For this course,
6464
it is shown as blanks to make it easier to cut/paste code samples.
@@ -152,7 +152,10 @@ bash % python3 sears.py
152152
6 32 0.00352
153153
...
154154
21 1048576 115.34336
155-
22 2097152 230.68672 Number of days 23 Number of bills 4194304 Final height 461.37344
155+
22 2097152 230.68672
156+
Number of days 23
157+
Number of bills 4194304
158+
Final height 461.37344
156159
```
157160

158161
Using this program as a guide, you can learn a number of important core concepts about Python.
@@ -238,7 +241,7 @@ while num_bills * bill_thickness < sears_height:
238241
day = day + 1
239242
num_bills = num_bills * 2
240243

241-
print('Number of days', days)
244+
print('Number of days', day)
242245
```
243246

244247
The statements indented below the `while` will execute as long as the expression after the `while` is `true`.
@@ -254,7 +257,7 @@ while num_bills * bill_thickness < sears_height:
254257
day = day + 1
255258
num_bills = num_bills * 2
256259

257-
print('Number of days', days)
260+
print('Number of days', day)
258261
```
259262

260263
Indentation groups the following statements together as the operations that repeat:

Notes/01_Introduction/03_Numbers.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ c = -1.345e-10
7777
Floats are represented as double precision using the native CPU representation [IEEE 754](https://en.wikipedia.org/wiki/IEEE_754).
7878
This is the same as the `double` type in the programming language C.
7979

80-
> 17 digits or precision
80+
> 17 digits of precision
8181
> Exponent from -308 to 308
8282
8383
Be aware that floating point numbers are inexact when representing decimals.
8484

8585
```python
8686
>>> a = 2.1 + 4.2
87-
>>> a === 6.3
87+
>>> a == 6.3
8888
False
8989
>>> a
9090
6.300000000000001
@@ -106,7 +106,7 @@ x ** y Power
106106
abs(x) Absolute Value
107107
```
108108

109-
Theses are the same operators as Integers, except for the bit-wise operators.
109+
These are the same operators as Integers, except for the bit-wise operators.
110110
Additional math functions are found in the `math` module.
111111

112112
```python
@@ -163,7 +163,7 @@ Try it out.
163163
3
164164
>>> b = '3.14159' # It also works with strings containing numbers
165165
>>> float(b)
166-
3.15159
166+
3.14159
167167
>>>
168168
```
169169

@@ -213,14 +213,15 @@ Modify the program so that extra payment information can be more generally handl
213213
Make it so that the user can set these variables:
214214

215215
```python
216-
extra_payment_start_month = 60
216+
extra_payment_start_month = 61
217217
extra_payment_end_month = 108
218218
extra_payment = 1000
219219
```
220220

221221
Make the program look at these variables and calculate the total paid appropriately.
222222

223-
How much will Dave pay if he pays an extra $1000/month for 4 years starting in year 5 of the mortgage?
223+
How much will Dave pay if he pays an extra $1000/month for 4 years starting after the first
224+
five years have already been paid?
224225

225226
### Exercise 1.10: Making a table
226227

@@ -234,15 +235,16 @@ The output should look something like this:
234235
4 10736.44 497581.83
235236
5 13420.55 496970.98
236237
...
237-
308 875705.88 674.44
238-
309 878389.99 -2006.86
239-
Total paid 878389.99
240-
Months 309
238+
308 874705.88 3478.83
239+
309 877389.99 809.21
240+
310 880074.1 -1871.53
241+
Total paid 880074.1
242+
Months 310
241243
```
242244

243245
### Exercise 1.11: Bonus
244246

245-
While you’re at it, fix the program to correct the for overpayment that occurs in the last month.
247+
While you’re at it, fix the program to correct for the overpayment that occurs in the last month.
246248

247249
### Exercise 1.12: A Mystery
248250

Notes/01_Introduction/04_Strings.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# 1.4 Strings
44

5-
This section introduces way to work with text.
5+
This section introduces ways to work with text.
66

77
### Representing Literal Text
88

@@ -28,8 +28,8 @@ Normally strings may only span a single line. Triple quotes capture all text enc
2828
including all formatting.
2929

3030
There is no difference between using single (') versus double (")
31-
quotes. The same type of quote used to start a string must be used to
32-
terminate it.
31+
quotes. *However, the same type of quote used to start a string must be used to
32+
terminate it*.
3333

3434
### String escape codes
3535

@@ -42,7 +42,7 @@ directly at the keyboard. Here are some common escape codes:
4242
'\t' Tab
4343
'\'' Literal single quote
4444
'\"' Literal double quote
45-
'\\'` Literal backslash
45+
'\\' Literal backslash
4646
```
4747

4848
### String Representation
@@ -54,7 +54,7 @@ an integer. You can specify an exact code-point value using the following escap
5454
a = '\xf1' # a = 'ñ'
5555
b = '\u2200' # b = '∀'
5656
c = '\U0001D122' # c = '𝄢'
57-
d = '\N{FORALL}' # d = '∀'
57+
d = '\N{FOR ALL}' # d = '∀'
5858
```
5959

6060
The [Unicode Character Database](https://unicode.org/charts) is a reference for all
@@ -77,7 +77,7 @@ You can also slice or select substrings specifying a range of indices with `:`.
7777
```python
7878
d = a[:5] # 'Hello'
7979
e = a[6:] # 'world'
80-
f = a[3:8] # 'lowo'
80+
f = a[3:8] # 'lo wo'
8181
g = a[-5:] # 'world'
8282
```
8383

@@ -134,7 +134,7 @@ t = s.replace('Hello' , 'Hallo') # 'Hallo world'
134134
**More string methods:**
135135

136136
Strings have a wide variety of other methods for testing and manipulating the text data.
137-
This is small sample of methods:
137+
This is a small sample of methods:
138138

139139
```python
140140
s.endswith(suffix) # Check if string ends with suffix
@@ -144,7 +144,7 @@ s.isalpha() # Check if characters are alphabetic
144144
s.isdigit() # Check if characters are numeric
145145
s.islower() # Check if characters are lower-case
146146
s.isupper() # Check if characters are upper-case
147-
s.join(slist) # Joins lists using s as delimiter
147+
s.join(slist) # Join a list of strings using s as delimiter
148148
s.lower() # Convert to lower case
149149
s.replace(old,new) # Replace text
150150
s.rfind(t) # Search for t from end of string

Notes/01_Introduction/05_Lists.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ t = sorted(s) # s unchanged, t holds sorted values
157157
>>> nums * 2
158158
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
159159
>>> nums + [10, 11, 12, 13, 14]
160-
[1, 2, 3, 4, 5, 10, 11, 12, 13, 14] >>>
160+
[1, 2, 3, 4, 5, 10, 11, 12, 13, 14]
161161
```
162162

163163
Specifically, lists don't represent vectors/matrices as in MATLAB, Octave, R, etc.

Notes/01_Introduction/06_Files.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ To read a file line-by-line, use a for-loop like this:
136136

137137
```python
138138
>>> with open('Data/portfolio.csv', 'rt') as f:
139-
for line in f:
140-
print(line, end='')
139+
for line in f:
140+
print(line, end='')
141141

142142
name,shares,price
143143
"AA",100,32.20
@@ -220,14 +220,17 @@ Try it:
220220

221221
```python
222222
>>> import gzip
223-
>>> with gzip.open('Data/portfolio.csv.gz') as f:
223+
>>> with gzip.open('Data/portfolio.csv.gz', 'rt') as f:
224224
for line in f:
225225
print(line, end='')
226226

227227
... look at the output ...
228228
>>>
229229
```
230230

231+
Note: Including the file mode of `'rt'` is critical here. If you forget that,
232+
you'll get byte strings instead of normal text strings.
233+
231234
### Commentary: Shouldn't we being using Pandas for this?
232235

233236
Data scientists are quick to point out that libraries like

Notes/02_Working_with_data/00_Overview.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[Contents](../Contents.md) \| [Prev (1 Introduction to Python)](../01_Introduction/00_Overview.md) \| [Next (3 Program Organization)](../03_Program_organization/00_Overview.md)
2+
13
# 2. Working With Data
24

35
To write useful programs, you need to be able to work with data.
@@ -14,4 +16,4 @@ into Python's underlying object model.
1416
* [2.6 List comprehensions](06_List_comprehension.md)
1517
* [2.7 Object model](07_Objects.md)
1618

17-
[Contents](../Contents.md)
19+
[Contents](../Contents.md) \| [Prev (1 Introduction to Python)](../01_Introduction/00_Overview.md) \| [Next (3 Program Organization)](../03_Program_organization/00_Overview.md)

0 commit comments

Comments
 (0)