PK ĢiAļ
,Ŗ Andys_Corner_1/01-Hello.en.srt1
00:00:00,000 --> 00:00:02,000
Hi. I'm Andy.
2
00:00:02,000 --> 00:00:08,000
I graduated college in 2009, and I started traveling the world, biking across the country,
3
00:00:08,000 --> 00:00:10,000
and basically living the life of a drifter.
4
00:00:10,000 --> 00:00:13,000
When I found out about Udacity, I decided this was the job for me.
5
00:00:13,000 --> 00:00:17,000
Last semester I TA'd Sebastian's class on Programming a Robotic Car,
6
00:00:17,000 --> 00:00:21,000
and this semester I'm going to be TAing Peter's class on the Design of Computer Programs.
7
00:00:21,000 --> 00:00:24,000
I'm going to be available in the forums to help you with your questions,
8
00:00:24,000 --> 00:00:28,000
I'm going to record supplementary videos when there's things that seem confusing,
9
00:00:28,000 --> 00:00:31,000
and I'll be there for you to yell at in case the grading scripts don't work,
10
00:00:31,000 --> 99:59:59,000
though I think we've got most of those bugs ironed out. See you in class.
PK ĪiA)U«
«
. Andys_Corner_1/02-List_Comprehensions_1.en.srt1
00:00:00,000 --> 00:00:02,000
[Andy] This lesson is on list comprehensions.
2
00:00:02,000 --> 00:00:06,000
This is something that wasn't covered in CS101 but will be used in many future classes,
3
00:00:06,000 --> 00:00:08,000
including CS212.
4
00:00:08,000 --> 00:00:12,000
List comprehensions are a powerful tool for quickly and concisely creating lists.
5
00:00:12,000 --> 00:00:17,000
For example, let's say you have a list of the Udacity TAs like this,
6
00:00:17,000 --> 00:00:19,000
and maybe we'll want to write the TA names in uppercase
7
00:00:19,000 --> 00:00:21,000
because lowercase is a little bit boring.
8
00:00:21,000 --> 00:00:25,000
One way we can do this is with a for loop like this one. And let's see how it works.
9
00:00:25,000 --> 00:00:28,000
This for loop is really doing 5 different things.
10
00:00:28,000 --> 00:00:32,000
First we create the empty list baduppercasetas,
11
00:00:32,000 --> 00:00:34,000
and I've called it baduppercasetas
12
00:00:34,000 --> 00:00:38,000
to emphasize that this really isn't the way we're going to want to create such a list.
13
00:00:38,000 --> 00:00:42,000
Next it generates the indices, and it does that here.
14
00:00:42,000 --> 00:00:49,000
These indices will be 0, 1, 2, 3, 4, 5 because udacitytas is a list of length 6.
15
00:00:49,000 --> 00:00:52,000
Then we iterate over these indices.
16
00:00:52,000 --> 00:00:56,000
Next we apply the upper function, and this is a function that just takes a string
17
00:00:56,000 --> 00:00:59,000
and converts all of the characters to uppercase.
18
00:00:59,000 --> 00:01:03,000
Finally, we append to the baduppercasetas list.
19
00:01:03,000 --> 00:01:13,000
And this code will be perfectly functional, but it is bad, it is ugly, and it is slow,
20
00:01:13,000 --> 00:01:15,000
which is why we have list comprehensions.
21
00:01:15,000 --> 00:01:19,000
And just to show that this code works, let's run it.
22
00:01:19,000 --> 00:01:22,000
And sure enough, we get a list of the TA names, and they are printed in uppercase.
23
00:01:22,000 --> 00:01:26,000
Using list comprehensions we could solve this problem in 1 line of code.
24
00:01:26,000 --> 00:01:31,000
And here Python recognizes that udacitytas is an iterable.
25
00:01:31,000 --> 00:01:35,000
Iterable just means any object that can be iterated over.
26
00:01:35,000 --> 00:01:39,000
So for example, lists can be iterated over, strings can--and you'll see a lot of that
27
00:01:39,000 --> 00:01:45,000
in CS212 in the first unit--tuples--and if you don't know what those are yet, don't worry.
28
00:01:45,000 --> 00:01:48,000
These are all iterable objects, and this notation tells Python
29
00:01:48,000 --> 00:01:55,000
to iterate over all of the entries in udacitytas, call each entry name,
30
00:01:55,000 --> 00:01:58,000
and then apply this upper function to name.
31
00:01:58,000 --> 00:02:02,000
The brackets indicate that we want to put the results into a list,
32
00:02:02,000 --> 00:02:05,000
and that's the list that we see down here:
33
00:02:05,000 --> 00:02:09,000
Peter, Andy, Sarah, Gundega, Job, Sean.
34
00:02:09,000 --> 00:02:14,000
And actually, I'd rather print each name on its own line, so let's do that like this.
35
00:02:17,000 --> 00:02:19,000
That's better.
PK ŠiAń ;p p . Andys_Corner_1/03-List_Comprehensions_2.en.srt1
00:00:00,000 --> 00:00:03,000
[Andy] Now, what if our data structure was a bit more complicated
2
00:00:03,000 --> 00:00:05,000
than a list with strings as entries?
3
00:00:05,000 --> 00:00:10,000
Here we have a list where each entry is a tuple, as indicated by these parentheses.
4
00:00:10,000 --> 00:00:15,000
For now let's just think of tuples as unchangeable or immutable lists.
5
00:00:15,000 --> 00:00:21,000
Each of these tuples contains a TA name, the country where that TA lives,
6
00:00:21,000 --> 00:00:24,000
and the course which that TA is currently instructing.
7
00:00:24,000 --> 00:00:28,000
This data is interesting, but I'd rather have it presented to me as a list of sentences,
8
00:00:28,000 --> 00:00:31,000
and we can do that with list comprehensions.
9
00:00:31,000 --> 00:00:34,000
So here we've turned tadata into a list of strings,
10
00:00:34,000 --> 00:00:37,000
and each of those strings is a sentence about a TA.
11
00:00:37,000 --> 00:00:42,000
For example, Peter lives in USA and is the TA for CS262.
12
00:00:42,000 --> 00:00:44,000
How do we do that?
13
00:00:44,000 --> 00:00:47,000
We use the same sort of list comprehension we used last time,
14
00:00:47,000 --> 00:00:53,000
but now tadata is an iterable and its entries are tuples.
15
00:00:53,000 --> 00:01:02,000
These tuples each have 3 entries, and when we reference these names here, here, and here,
16
00:01:02,000 --> 00:01:04,000
Python understands what we're talking about.
17
00:01:04,000 --> 00:01:06,000
Now let's have a quiz.
18
00:01:06,000 --> 00:01:09,000
Using the same structure for tadata that we had before,
19
00:01:09,000 --> 00:01:14,000
I want to construct sentences but only about the country in which each TA lives.
20
00:01:14,000 --> 00:01:16,000
For example, Peter lives in USA,
21
00:01:16,000 --> 00:01:18,000
or Gundega lives in Latvia.
22
00:01:18,000 --> 00:01:21,000
I've given you 3 options for possible list comprehensions
23
00:01:21,000 --> 00:01:23,000
that may accomplish this task--
24
00:01:23,000 --> 00:01:28,000
that given tadata will produce the correct tacountry.
25
00:01:28,000 --> 00:01:31,000
And so which of the following list comprehensions will work?
26
00:01:31,000 --> 00:01:33,000
Check all that apply.
PK ŃiAĘ
ėć ć 7 Andys_Corner_1/04-List_Comprehensions_2_Solution.en.srt1
00:00:00,000 --> 00:00:02,000
And let's go through each of the options.
2
00:00:02,000 --> 00:00:04,000
This first option will not work.
3
00:00:04,000 --> 00:00:06,000
Since tadata is a tuple
4
00:00:06,000 --> 00:00:11,000
containing 3 elements, we need to reference each of those 3 elements
5
00:00:11,000 --> 00:00:13,000
for Python to understand what we want.
6
00:00:13,000 --> 00:00:15,000
Here we only reference name, country;
7
00:00:15,000 --> 00:00:18,000
we don't even reference course at all,
8
00:00:18,000 --> 00:00:21,000
so Python gets confused and if you try to run this you will get an error.
9
00:00:21,000 --> 00:00:24,000
The second option looks great.
10
00:00:24,000 --> 00:00:26,000
It's readable; name, plus lives in country
11
00:00:26,000 --> 00:00:28,000
is very easy to understand.
12
00:00:28,000 --> 00:00:31,000
It references all 3 variables in tadata.
13
00:00:31,000 --> 00:00:35,000
Looks like I forgot my closed brackets here.
14
00:00:35,000 --> 00:00:38,000
This third option will also work.
15
00:00:38,000 --> 00:00:40,000
It has 2 variable names,
16
00:00:40,000 --> 00:00:44,000
and we reference all 3 elements in the tuple,
17
00:00:44,000 --> 00:00:46,000
but I don't like this one as much as the second one.
18
00:00:46,000 --> 00:00:49,000
The reason being "x lives in y"
19
00:00:49,000 --> 00:00:53,000
doesn't remind me that I'm talking about a name and a country.
20
00:00:53,000 --> 00:00:55,000
As far as readability is concerned,
21
00:00:55,000 --> 00:00:57,000
I prefer option 2.
22
00:00:57,000 --> 00:01:00,000
And, you can see, if we try to run option 1,
23
00:01:00,000 --> 00:01:04,000
we get an error message--value error--
24
00:01:04,000 --> 00:01:06,000
too many values to unpack.
25
00:01:06,000 --> 00:01:08,000
If we run option 2 or 3 however,
26
00:01:08,000 --> 00:01:10,000
we get exactly what we want.
PK ÓiAņ|ū . Andys_Corner_1/05-List_Comprehensions_3.en.srt1
00:00:00,000 --> 00:00:02,000
Let's introduce one more feature into our list comprehensions.
2
00:00:02,000 --> 00:00:05,000
Remember tadata and tafacts.
3
00:00:05,000 --> 00:00:09,000
When we ran this, we got a list of strings
4
00:00:09,000 --> 00:00:12,000
which each contained a fact about a TA.
5
00:00:12,000 --> 00:00:14,000
Like: Job lives in the USA,
6
00:00:14,000 --> 00:00:16,000
and is the TA for CS387.
7
00:00:16,000 --> 00:00:21,000
Well, what if we only want facts about TAs that don't live in the USA?
8
00:00:21,000 --> 00:00:27,000
So, in this case that would be Gundega and Sarah.
9
00:00:27,000 --> 00:00:30,000
Well, since these TAs are working remotely,
10
00:00:30,000 --> 00:00:33,000
let's call it remotetafacts,
11
00:00:33,000 --> 00:00:37,000
and all we have to do is add a simple "if" statement.
12
00:00:37,000 --> 00:00:41,000
And now when we run this, we only get these two strings
13
00:00:41,000 --> 00:00:43,000
about Sarah and Gundega.
14
00:00:43,000 --> 00:00:45,000
The addition we made was pretty intuitive.
15
00:00:45,000 --> 00:00:50,000
This "if" statement just says: "If the country is not the USA,"
16
00:00:50,000 --> 00:00:52,000
then we're going to add an entry
17
00:00:52,000 --> 00:00:54,000
according to the rules we described earlier.
18
00:00:54,000 --> 00:00:57,000
I hope you learned a lot about list comprehensions.
19
00:00:57,000 --> 00:00:59,000
You should feel free to click the link below the video to learn even more,
20
00:00:59,000 --> 00:01:02,000
but now it's time to practice.
PK ÓiA·÷) . Andys_Corner_1/06-List_Comprehensions_4.en.srt1
00:00:00,000 --> 00:00:03,000
Use list comprehensions to identify all the TAs
2
00:00:03,000 --> 00:00:06,000
who are teaching a 300-level course.
3
00:00:06,000 --> 00:00:08,000
So that's any course beginning with the number 3,
4
00:00:08,000 --> 00:00:11,000
which in this case will be Gundega and Job.
5
00:00:11,000 --> 00:00:14,000
You may want to use the string.find method to help you out here.
6
00:00:14,000 --> 00:00:18,000
Your variable, ta300, should look exactly like this.
PK ŌiA\čŃz z 7 Andys_Corner_1/07-List_Comprehensions_4_Solution.en.srt1
00:00:00,000 --> 00:00:03,000
And this is how I solved the problem.
2
00:00:03,000 --> 00:00:06,000
I assigned ta300 to name + is the TA for
3
00:00:06,000 --> 00:00:10,000
+ course for name, country, course in tadata.
4
00:00:10,000 --> 00:00:14,000
And, notice I had to use this country
5
00:00:14,000 --> 00:00:17,000
even though it didn't show up here
6
00:00:17,000 --> 00:00:21,000
and that's because each of these lists contain 3 elements
7
00:00:21,000 --> 00:00:23,000
and I need to reference all three of those elements.
8
00:00:23,000 --> 00:00:29,000
I only did this if course.find for this string CS3--
9
00:00:29,000 --> 00:00:32,000
because you'll notice all of the 300 level classes
10
00:00:32,000 --> 00:00:35,000
have CS3 in them--was not equal to negative one.
11
00:00:35,000 --> 00:00:38,000
Because, remember, find returns negative one
12
00:00:38,000 --> 00:00:40,000
when it doesn't find what you're asking for.
13
00:00:40,000 --> 00:00:43,000
And when I run this, I get exactly what I want.
14
00:00:44,000 --> 00:00:47,000
Good work.
PK ÕiArÅ Å ' Andys_Corner_1/08-Rules_Of_Poker.en.srt1
00:00:00,232 --> 00:00:02,981
The first unit of CS212 uses poker as a vehicle to
2
00:00:02,981 --> 00:00:05,849
teach about the design of computer programs. If you
3
00:00:05,849 --> 00:00:07,899
donāt know the rules of poker yet, donāt worry, thatās
4
00:00:07,899 --> 00:00:10,452
exactly what this video is for. Now of all you know
5
00:00:10,452 --> 00:00:12,527
about poker is what youāve seen on TV or in a
6
00:00:12,527 --> 00:00:15,216
casino, you may think itās pretty complicated. There
7
00:00:15,216 --> 00:00:17,932
is that intimidating green table and itās surrounded
8
00:00:17,932 --> 00:00:21,129
by some very serious looking people and these
9
00:00:21,129 --> 00:00:24,412
people often have very silly hats or ridiculous
10
00:00:24,412 --> 00:00:30,613
sunglasses and they are saying things like, raise, or
11
00:00:30,613 --> 00:00:33,765
all-in. Now if you ever want to actually play poker,
12
00:00:33,765 --> 00:00:35,648
you are going to have to learn what all this means.
13
00:00:35,648 --> 00:00:37,340
There is betting, there is folding, there is calling,
14
00:00:37,340 --> 00:00:40,474
there is raising, and it can get pretty complicated.
15
00:00:40,474 --> 00:00:42,445
There is a lot of strategy involved. But for the
16
00:00:42,445 --> 00:00:45,442
purposes of this unit, we only need to know the most
17
00:00:45,442 --> 00:00:48,396
basic aspect of poker and this aspect is common to
18
00:00:48,396 --> 00:00:52,099
every single variation of poker and thatās how hands
19
00:00:52,099 --> 00:00:53,946
are arranged because at the end of the day, all of
20
00:00:53,946 --> 00:00:55,917
these different versions of poker have to do with
21
00:00:55,917 --> 00:00:58,451
making the best five card hand that you can. Now
22
00:00:58,451 --> 00:01:00,722
these different hands each have different names and
23
00:01:00,722 --> 00:01:02,677
there are nine of them. So letās talk about what each
24
00:01:02,677 --> 00:01:05,242
of these names mean and since this class uses
25
00:01:05,242 --> 00:01:07,958
python, Iāll start my numbering at zero.
26
00:01:07,958 --> 00:01:10,194
The best hand and this one that you almost never
27
00:01:10,194 --> 00:01:13,761
see in poker is the straight flush and here we have a
28
00:01:13,761 --> 00:01:16,917
straight flush. The suit here is hearts, so you can
29
00:01:16,917 --> 00:01:19,441
see every single card is a heart and they are all in
30
00:01:19,441 --> 00:01:23,358
sequential order, nine, ten, jack, queen, king. If you
31
00:01:23,358 --> 00:01:26,629
ever go into a poker form online, you would see
32
00:01:26,629 --> 00:01:32,276
these cards were in as 9H, TH, JH, QH, KH and
33
00:01:32,276 --> 00:01:34,123
thatās the system weāre going to use here.
34
00:01:34,123 --> 00:01:36,844
The next best hand is four of a kind and here we
35
00:01:36,844 --> 00:01:41,178
have a four of a kind with four aces and a six. The
36
00:01:41,178 --> 00:01:44,185
six is usually irrelevant to this hand but weāll talk a
37
00:01:44,185 --> 00:01:47,116
little bit about how to break ties in class. Next best is
38
00:01:47,116 --> 00:01:51,234
the full house and a full house is just three cards of
39
00:01:51,234 --> 00:01:53,615
one rank, so here we have three tens and two of
40
00:01:53,615 --> 00:01:57,005
another, so two, twos. This hand is a full house so
41
00:01:57,005 --> 00:02:00,386
we would call it tens full of twos. Next is the flush
42
00:02:00,386 --> 00:02:05,280
and a flush is five cards of the same suit and here
43
00:02:05,280 --> 00:02:07,047
the ranks donāt matter. You can see we have a
44
00:02:07,047 --> 00:02:10,879
three, six, jack, queen and king but theyāre all of the
45
00:02:10,879 --> 00:02:15,214
suit spade. Next we have the street and a street is
46
00:02:15,214 --> 00:02:17,876
just five cards in sequential order, five, six, seven,
47
00:02:17,876 --> 00:02:21,009
eight, nine and here the suit doesnāt matter at all.
48
00:02:21,009 --> 00:02:24,074
We have a spade, diamond, club, diamond and
49
00:02:24,074 --> 00:02:27,699
another spade. Our next hand is the three of a kind
50
00:02:27,699 --> 00:02:30,847
and three of a kind is just three cards of the same
51
00:02:30,847 --> 00:02:35,299
rank, so these three fours are whatās relevant. The
52
00:02:35,299 --> 00:02:37,969
queen and again in some special circumstances
53
00:02:37,969 --> 00:02:41,581
where weāre playing with multiple decks, they may
54
00:02:41,581 --> 00:02:43,177
be used to break a tie and again weāll talk about that
55
00:02:43,177 --> 00:02:48,460
in class. Next we have two pair, for example, a pair
56
00:02:48,460 --> 00:02:51,662
of jacks and a pair of nines would be two pair. The
57
00:02:51,662 --> 00:02:55,058
second worst hand is a pair and a pair is just two
58
00:02:55,058 --> 00:02:57,808
cards of the same rank, here we have two threes.
59
00:02:57,808 --> 00:03:00,593
The eight, five, two donāt do much to help our hand
60
00:03:00,593 --> 00:03:06,158
here. Finally, we have nothing. So we could also call
61
00:03:06,158 --> 00:03:10,072
that high card because when two people who have
62
00:03:10,072 --> 00:03:13,341
nothing show down their hands, the one with the
63
00:03:13,341 --> 00:03:16,485
highest card wins.
64
00:03:16,485 --> 00:03:21,533
Here we have king high and this is really quite a bad
65
00:03:21,533 --> 00:03:23,653
hand. If you are ever in a casino, I wouldnāt go
66
00:03:23,653 --> 00:03:27,442
playing this and expecting win. And thatās it; those
67
00:03:27,442 --> 00:03:30,214
are our nine hands, straight flush, four of a kind, full
68
00:03:30,214 --> 00:03:33,905
house, flush, straight, three of a kind, two pair, pair
69
00:03:33,905 --> 00:03:36,410
and nothing. Noticeably design them all in number,
70
00:03:36,410 --> 00:03:39,487
zero through eight. This is one of the numbers weāll
71
00:03:39,487 --> 00:03:42,904
be using in our poker program to compare hands. It
72
00:03:42,904 --> 00:03:45,114
turns out, weāll need a few other numbers to
73
00:03:45,114 --> 00:03:48,818
distinguish between for example two full houses, six
74
00:03:48,818 --> 00:03:51,246
for six is inadequate, weāll need to add some other
75
00:03:51,246 --> 00:03:54,127
numbers in there but weāll explain that in class and
76
00:03:54,127 --> 00:03:56,201
for now you should understand the rules of poker
77
00:03:56,201 --> 00:03:59,000
well enough to follow on.
PK ĢiAļ
,Ŗ ¤ Andys_Corner_1/01-Hello.en.srtPK ĪiA)U«
«
. ¤V Andys_Corner_1/02-List_Comprehensions_1.en.srtPK ŠiAń ;p p . ¤M Andys_Corner_1/03-List_Comprehensions_2.en.srtPK ŃiAĘ
ėć ć 7 ¤ Andys_Corner_1/04-List_Comprehensions_2_Solution.en.srtPK ÓiAņ|ū . ¤A$ Andys_Corner_1/05-List_Comprehensions_3.en.srtPK ÓiA·÷) . ¤+ Andys_Corner_1/06-List_Comprehensions_4.en.srtPK ŌiA\čŃz z 7 ¤r- Andys_Corner_1/07-List_Comprehensions_4_Solution.en.srtPK ÕiArÅ Å ' ¤A2 Andys_Corner_1/08-Rules_Of_Poker.en.srtPK Ū KM