text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
have been pretty simple and I've just
7,105.96
3.44
created one student but certainly if I
7,107.36
3.759
spent more time and wrote more code you
7,109.4
4.04
could imagine writing one program that
7,111.119
4.361
has a list of students many more
7,113.44
4.32
students than just the one we keep
7,115.48
4.4
demonstrating yet it would be a little
7,117.76
4.08
weird it's a little inconsistent with
7,119.88
3.839
the real or the Fantasy World of Harry
7,121.84
4.64
Potter to instantiate one two three or
7,123.719
5.161
more sorting hats there really is just
7,126.48
4.92
one really one Singleton if you will
7,128.88
3.96
which is a term of Art in a lot of
7,131.4
3.92
context of programming so let me propose
7,132.84
4.2
that we actually improve the design of
7,135.32
3.96
the Sorting Hat so that we don't have to
7,137.04
5.159
instantiate a Sorting Hat because right
7,139.28
5
now this is kind of allowing me to do
7,142.199
4.4
something like hat one equals hat hat
7,144.28
4.68
two equals hat hat three equals and so
7,146.599
3.841
forth I don't really need that
7,148.96
3.759
capability I really just need to
7,150.44
4.799
represent the Sorting Hat with a class
7,152.719
4.281
but I don't really need to instantiate
7,155.239
3.4
it why because it already exists I need
7,157
5.199
just one so it turns out in Python that
7,158.639
5.201
up until now we've been using as I keep
7,162.199
4.081
calling them instance methods writing
7,163.84
4.72
functions inside of classes that are
7,166.28
4.76
automatically past a reference to self
7,168.56
4.519
the current object but sometimes you
7,171.04
3.76
just don't need that sometimes it
7,173.079
3.921
suffices to just know what the class is
7,174.8
4.04
and assume that there might not even be
7,177
4.28
any objects of that class so in this
7,178.84
4.879
sense you can use a class really is a
7,181.28
5.52
container for data Andor functionality
7,183.719
5.641
that is just somehow conceptually
7,186.8
6
related things related to assorting hats
7,189.36
5
and there's this other decorator or
7,192.8
3.72
function called class method that allows
7,194.36
3.96
us to do just this so let me go back to
7,196.52
4.8
my code here and let me propose that if
7,198.32
5.839
I'm not going to instantiate multiple
7,201.32
5.359
houses I don't really need this init
7,204.159
3.96
method because that's really meant to
7,206.679
4.121
initialize specific objects from that
7,208.119
5.281
blueprint that template that mold so let
7,210.8
4.72
me get rid of this but if I get rid of
7,213.4
4.52
this I no longer have access to self but
7,215.52
4.719
that's okay because it turns out in
7,217.92
5.36
addition to their existing class methods
7,220.239
5.201
there are also what we might call class
7,223.28
5.6
variables and class variables exist
7,225.44
6
within the class itself and there's just
7,228.88
5.799
one copy of that variable for all of the
7,231.44
5.4
objects thereof they all share if you
7,234.679
4.96
will the same variable be it an INT or
7,236.84
5.239
stir or in this case a list so what I've
7,239.639
6.201
done here is Define inside of my hat
7,242.079
8.12
class in a class variable called houses
7,245.84
6.359
I don't say self because self is no
7,250.199
3.88
longer relevant self refers to specific
7,252.199
4.761
objects I want a variable inside of this
7,254.079
5.761
class AKA a class variable that equals
7,256.96
5.119
that list because it's inside of this
7,259.84
6.359
hat now class I can use that list in any
7,262.079
5.961
of my functions I've only got one now
7,266.199
3.721
called sort but if I had more it would
7,268.04
3.76
be accessible to all of those methods as
7,269.92
4.759
well and with sort it also doesn't
7,271.8
5.319
really make sense to sort within a
7,274.679
4
specific sorting hack because again
7,277.119
3.761
there only want there to be one so I can
7,278.679
4.44
actually specify that this is a class
7,280.88
5.239
method by saying at class method and I
7,283.119
5.681
don't pass in self anymore I actually by
7,286.119
5.321
convention pass in the a reference to
7,288.8
5.319
the class itself it's typically written
7,291.44
7.239
as CLS why well if you wrote C ass that
7,294.119
6.681
would actually conflict with the keyword
7,298.679
4.48
class that we keep using up here so the
7,300.8
4.56
world realized that oops we uh can't
7,303.159
4.201
reuse that same phrase here so let's
7,305.36
4.319
just call this class this this is useful
7,307.36
4.56
in some context including this one why
7,309.679
4.96
well notice what I can now do I can now
7,311.92
5.96
change self to be just class why because
7,314.639
5.881
house is now not an instance variable
7,317.88
5.44
accessible via self. houses it is now a
7,320.52
6
class variable accessible via class.
7,323.32
6.12
houses or technically CLS do houses in
7,326.52
5.559
this case but now the final flourish is
7,329.44
6.04
this now I don't have to instantiate any
7,332.079
7.16
hat objects as I used to on here line 13
7,335.48
6
I can just use functionality that comes
7,339.239
4.201
with this class so I'm going to delete
7,341.48
3.84
that line Al together I'm going to
7,343.44
4.88
capitalize the Hat on this new line 13
7,345.32
7.08
and just say hat. sort quote unquote
7,348.32
6.759