Skip to content

Commit 468c179

Browse files
committed
Python curriculum updates
1 parent 3438e1d commit 468c179

File tree

11 files changed

+49
-37
lines changed

11 files changed

+49
-37
lines changed

advanced-python/PITCHME.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ RTFM: https://pip.pypa.io/
3030

3131
---
3232
## Map
33-
Applies a function to list elements
33+
Applies a function to a list, element by element
3434
```python
3535
names = ["sam", "john", "james"]
3636
map(len, names)
@@ -50,6 +50,15 @@ def sqr(x): return x ** 2
5050
map(sqr, map(len,names))
5151
```
5252

53+
---
54+
## Filter
55+
Remove items from a list
56+
```python
57+
def too_old(x): return x > 30
58+
ages = [22, 25, 29, 34, 56, 24, 12]
59+
filter(too_old, ages)
60+
```
61+
5362
---
5463
## Lambda
5564
A function without a name
@@ -66,15 +75,6 @@ squares = map((lambda x: x ** 2), items)
6675
Note:
6776
What does "pythonic" mean - all programming languages expose the same fundamentals, but what makes one different from the other? Syntax & semantics, sure, but developers also like to build concensus around conventions.
6877

69-
---
70-
## Filter
71-
Remove items from a list
72-
```python
73-
def too_old(x): return x > 30
74-
ages = [22, 25, 29, 34, 56, 24, 12]
75-
filter(too_old, ages)
76-
```
77-
7878
---
7979
## Let's do it!
8080
![Hack](/assets/img/hack-600.png)

intro-to-python/PITCHME.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
---?include=/intro-to-python/topics/what-is-python.md
66
---?include=/intro-to-python/topics/hello-python.md
7-
---?include=/intro-to-python/topics/data-types.md
87
---?include=/intro-to-python/topics/string.md
98
---?include=/intro-to-python/topics/numeric.md
109
---?include=/intro-to-python/topics/list.md
11-
---?include=/intro-to-python/topics/dynamic-typing.md
10+
---?include=/intro-to-python/topics/data-types.md
1211
---?include=/intro-to-python/topics/dictionary.md
1312
---?include=/intro-to-python/topics/tuple.md
13+
---?include=/intro-to-python/topics/dynamic-typing.md
1414
---?include=/intro-to-python/topics/conditionals.md
1515
---?include=/intro-to-python/topics/loops.md
1616
---?include=/intro-to-python/topics/functions.md

intro-to-python/topics/conditionals.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* allows us to affect the *flow of control*
44
```python
55
sam = ("Sam Moorhouse", 1984)
6-
name, yob = sam
6+
(name, yob) = sam
77
if yob < 1990:
88
print (name + " is an old dude")
99
else:
@@ -26,6 +26,7 @@ else:
2626

2727
Note:
2828
* We cast the result of `raw_input` to `int`
29+
* What happens if we enter something that's not an `int`
2930
+++
3031
### Conditional Operators
3132

intro-to-python/topics/data-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ Every variable has a type...
1919
* Tuple
2020
* Byte
2121
* Byte Array
22-
* Range
22+
* Range

intro-to-python/topics/dictionary.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
## Dictionary
2-
A hash table
3-
* sequence of key-value pairs
4-
* efficient lookup & insertion
5-
* elements aren't ordered
2+
A hash table -- what does that mean?
3+
* An *association* -- a *key* is associated with a *value*
4+
* Like a dictionary that translates between languages
5+
* A basic data structure
6+
* Can be thought of as a list of pairs
7+
* Elements aren't ordered though
68

79
+++
810
## Dictionary
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,35 @@
11

22
## Dynamic typing
3-
* The *type* of a variable is determined at runtime
4-
* Not compile time
5-
* What's the difference?
3+
* Variables are storage that hold *values*
4+
* Should variables care what sort of values they hold?
5+
* This is another philosphical difference -- no right/wrong answers
6+
* Statically-typed languages: You have to say what sort of data variables can hold
7+
* Dynamically-typed: Variables can hold anything & can change their mind
8+
* Python is (mostly) dynamically-typed
69

710
+++
811

912
## Dynamic typing
1013
* Useful for writing code quickly
1114
* Fewer compiler errors
1215
* Where do the errors go?
16+
* Are there any problems that come from dynamic typing?
1317

1418
+++
1519
## Dynamic typing
16-
Sometimes they go nowhere:
20+
Sometimes problems can hide:
1721
```sh
1822
>>> print (names)
1923
['John', 'Paul', 'George', 3]
2024
```
2125

2226
+++
2327
## Dynamic typing
24-
Sometimes things break:
28+
Sometimes incorrect types break things:
2529
```sh
2630
>>> len(3)
2731
Traceback (most recent call last):
2832
File "<stdin>", line 1, in <module>
2933
TypeError: object of type 'int' has no len()
30-
```
34+
```
35+
The Traceback shows where the error occurred, and what sort of error it is

intro-to-python/topics/functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ print (tellMeASecret())
3636
def getHostPort():
3737
return ("nydev1", 3123)
3838

39-
host, port = getHostPort()
39+
(host, port) = getHostPort()
4040
```
4141

4242
+++

intro-to-python/topics/modules.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
+++
99
## Modules
1010
* `import package.subpackage.module`
11+
* You can install additional modules on your machine
1112

1213
+++
1314
## Modules
14-
* We're working mostly with functions
15-
* Everything in Python is an Object
15+
* We're working mostly with functions
1616
* Python has *much* more
1717
* Classes and objects
1818
* Inheritance
19+
* In fact, everything in Python is an Object

intro-to-python/topics/string.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## String
2-
Use "" or '', doesn't matter:
2+
Use "" or '', doesn't matter (unlike some other languages):
33
```sh
44
>>> print ("hello" == 'hello')
55
True

intro-to-python/topics/tuple.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A way to join related data:
44
hostport = ("accdev1", 3213)
55
```
66

7-
Tuple is immutable unlike python list
7+
Tuple is immutable unlike a python list
88

99
+++
1010
## Tuple
@@ -14,12 +14,12 @@ sam = ("Sam Moorhouse", 1984)
1414
```
1515
* What does *1984* refer to? (Careful!)
1616
* Is there a better way?
17-
17+
* How does this compare to maps?
1818

1919
+++
2020
## Tuple creation and destructuring
2121

22-
Destructuring the tuple means getting the values from the tuple in separate variables
22+
Destructuring the tuple means getting the values from the tuple in separate variables:
2323

2424
```
2525
ho_techical = ("Ghana", 5000, "Engineering")
@@ -34,4 +34,6 @@ print(no_student)
3434
3535
# print type of college
3636
print(type_ofcollege)
37-
```
37+
```
38+
39+
This is a form of what are called *records* in other languages

0 commit comments

Comments
 (0)