text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
python python allows you to pass
2,884.92
6.54
functions as arguments in two other
2,887.859
6.061
functions so get name is a function
2,891.46
5.94
sorted is a function and I'm passing in
2,893.92
7.5
get name to sort it as the value of that
2,897.4
6.9
key parameter now why am I doing that
2,901.42
4.439
well if you think of the get name
2,904.3
3.96
function as just a bunch a block of code
2,905.859
4.021
that will get the name of a student
2,908.26
3.48
that's handy because that's the
2,909.88
4.199
capability that sorted needs when given
2,911.74
3.9
a list of students Each of which is a
2,914.079
3.961
dictionary sorted needs to know how do I
2,915.64
3.84
get the name of the student in order to
2,918.04
3.12
do alphabetical sorting for you the
2,919.48
3.119
authors of python didn't know that we
2,921.16
2.88
were going to be creating students here
2,922.599
3
in this class so they couldn't have
2,924.04
3.84
anticipated writing code in advance that
2,925.599
3.901
specifically sorts on a field called
2,927.88
4.38
student let alone called name let alone
2,929.5
3.9
house
2,932.26
3.96
so what did they do they instead built
2,933.4
5.219
into the sorted function this named
2,936.22
4.74
parameter key that allows us all these
2,938.619
4.321
years later to tell their function
2,940.96
4.139
sorted how to sort this list of
2,942.94
4.679
dictionaries so now watch what happens
2,945.099
5.701
if I run python of students.pi and hit
2,947.619
6.48
enter I now have a sorted list of output
2,950.8
5.64
why because now that list of
2,954.099
5.281
dictionaries has all been sorted by the
2,956.44
4.02
student's name
2,959.38
3.66
I can further do this if as before we
2,960.46
3.899
want to reverse the whole thing by
2,963.04
3.18
saying reverse equals true we can do
2,964.359
3.421
that too let me rerun python of
2,966.22
3.3
students.pi and hit enter now it's
2,967.78
3.96
reverse now it's Ron then Hermione Harry
2,969.52
4.079
and Draco but we can do something
2,971.74
4.56
different as well what if I want to sort
2,973.599
5.941
for instance by house name reversed I
2,976.3
4.74
could do this I could change this
2,979.54
3.96
function from get name to get house I
2,981.04
4.079
could change the implementation up here
2,983.5
4.14
to be get house and I can return not the
2,985.119
4.141
student's name but the student's house
2,987.64
5.66
and so now notice if I run python of
2,989.26
7.44
students.pi enter notice now it is
2,993.3
6.299
sorted by house in reverse order
2,996.7
5.46
Slytherin is first and then Gryffindor
2,999.599
5.321
if I get rid of the reverse but keep the
3,002.16
5.34
get house and rerun this program now
3,004.92
5.639
it's sorted by house gryffindors first
3,007.5
5.52
and Slytherin is last and the upside now
3,010.559
4.441
of this is because I'm using this list
3,013.02
4.5
of dictionaries and keeping the students
3,015
4.859
data together until the last minute when
3,017.52
4.38
I'm finally do doing the printing I now
3,019.859
3.72
have full control over the information
3,021.9
4.199
itself and I can sort by this or that I
3,023.579
3.961
don't have to construct construct those
3,026.099
3.301
sentences in advance like I rather
3,027.54
4.38
hackishly did the first time all right
3,029.4
4.5
that was a lot let me pause here to see
3,031.92
4.139
if there are questions
3,033.9
4.74
so when when we're starting the files
3,036.059
5.901
should we every time should we use the
3,038.64
5.459
loops or
3,041.96
5.619
like uh like a dictionary or or any kind
3,044.099
7.681
of list can be sort by just sorting not
3,047.579
6.181
looping or
3,051.78
5.4
any kind of stuff a good question and
3,053.76
5.52
the short answer with python alone
3,057.18
4.32
you're the programmer you need to do the
3,059.28
4.559
Sorting with libraries and other
3,061.5
4.559
techniques absolutely you can do more of
3,063.839
4.201
this automatically because someone else
3,066.059
3.841
has written that code what we're doing
3,068.04
3.42
at the moment is doing everything from
3,069.9
3.419
scratch ourselves but absolutely with
3,071.46
3.3
other functions or libraries some of
3,073.319
4.26
this could be made uh more uh easily
3,074.76
5.339
done some of this could be made easier
3,077.579
4.321
other questions
3,080.099
4.861
on this technique here it's equal to the
3,081.9
7.02
returned value of the function can it be
3,084.96
10.32
equal to uh just uh a variable or a
3,088.92
9.12
value it well yes it should equal a
3,095.28
4.98
value so I'm speci and I should clarify
3,098.04
4.62
actually since this was not obvious
3,100.26
5.16
so when you pass in a function like get
3,102.66
5.52
name or get house to the sorted function
3,105.42
5.58
as the value of key that function is
3,108.18
6.3
automatically called by the get by the
3,111
6.24
sorted function for you on each of the
3,114.48
5.579
dictionaries in the list and it uses the
3,117.24
5.22
return value of get name or get house to
3,120.059
5.401
decide what strings to actually use to
3,122.46
5.28
compare in order to decide which is
3,125.46
4.74