text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
then I'm using not bracket zero or one | 2,644.02 | 4.14 |
because these are dictionaries now not | 2,646.24 | 5.579 |
list but why am I using single quotes to | 2,648.16 | 7.8 |
surround house and to surround name | 2,651.819 | 7.861 |
why single quotes inside of this | 2,655.96 | 6.659 |
F string | 2,659.68 | 7.8 |
to access those Keys yes um because you | 2,662.619 | 6.301 |
have double quotes | 2,667.48 | 4.139 |
in that in that line 12 and so you have | 2,668.92 | 6.24 |
to tell python to differentiate exactly | 2,671.619 | 4.98 |
because I'm already using double quotes | 2,675.16 | 4.08 |
outside of the F string if I want to put | 2,676.599 | 4.321 |
quotes around any strings on the inside | 2,679.24 | 3.9 |
which I do need to do for dictionaries | 2,680.92 | 4.32 |
because recall when you index into a | 2,683.14 | 4.02 |
dictionary you don't use numbers like | 2,685.24 | 4.68 |
lists 0 1 2 onward you instead use | 2,687.16 | 4.98 |
strings which need to be quoted but if | 2,689.92 | 3.899 |
you're already using double quotes it's | 2,692.14 | 3.479 |
easiest to then use single quotes on the | 2,693.819 | 3.601 |
inside so python doesn't get confused | 2,695.619 | 4.561 |
about what lines up with what so at the | 2,697.42 | 5.1 |
moment when I run this program it's | 2,700.18 | 4.26 |
going to print out those hellos but | 2,702.52 | 4.799 |
they're not yet sorted in fact what I | 2,704.44 | 6.419 |
now have is a list of dictionaries and | 2,707.319 | 5.52 |
nothing is yet sorted but let me tighten | 2,710.859 | 3.72 |
up the code too to point out that it | 2,712.839 | 3.961 |
doesn't need to be quite as verbose if | 2,714.579 | 4.081 |
you're in the habit of creating an empty | 2,716.8 | 3.66 |
dictionary like this on line six and | 2,718.66 | 3.659 |
then immediately putting in two keys | 2,720.46 | 4.32 |
name and house each with two values name | 2,722.319 | 4.321 |
and house respectively you can actually | 2,724.78 | 3.6 |
do this all at once so let me show you a | 2,726.64 | 3.66 |
slightly different different syntax I | 2,728.38 | 3.719 |
can do this give me a variable called | 2,730.3 | 4.5 |
student and let me use curly braces on | 2,732.099 | 4.141 |
the right hand side here but instead of | 2,734.8 | 3.24 |
leaving them empty let's just Define | 2,736.24 | 4.26 |
those keys and those values now quote | 2,738.04 | 5.1 |
unquote name will be name and quote | 2,740.5 | 5.46 |
unquote house will be house this | 2,743.14 | 4.979 |
achieves the exact same effect in one | 2,745.96 | 5.1 |
line instead of three it creates a new | 2,748.119 | 5.161 |
non-empty dictionary containing a name | 2,751.06 | 4.08 |
key the value of which is the student's | 2,753.28 | 3.96 |
name and a house key the value of which | 2,755.14 | 4.08 |
is the student's house nothing else | 2,757.24 | 3.48 |
needs to change that will still just | 2,759.22 | 4.02 |
work so that if I again run python if | 2,760.72 | 4.26 |
students.pi I'm still seeing those | 2,763.24 | 3.78 |
greetings but they're still not quite | 2,764.98 | 5.16 |
actually sorted well what might I go | 2,767.02 | 5.7 |
about doing here in order to what could | 2,770.14 | 5.1 |
I do to improve upon this further | 2,772.72 | 5.639 |
well we need some mechanism now of | 2,775.24 | 5.76 |
sorting those students but unfortunately | 2,778.359 | 6.48 |
you can't do this we can't sort all of | 2,781 | 6.42 |
the students now because those students | 2,784.839 | 4.621 |
are not names like they were before they | 2,787.42 | 3.48 |
aren't sentences like they were before | 2,789.46 | 4.08 |
each of the students is a dictionary and | 2,790.9 | 4.56 |
it's not obvious how you would sort a | 2,793.54 | 5.279 |
dictionary inside of a list so ideally | 2,795.46 | 5.7 |
what do we want to do if at the moment | 2,798.819 | 5.821 |
we hit line 9 we have a list of all of | 2,801.16 | 5.459 |
these students and inside of that list | 2,804.64 | 4.439 |
is one dictionary per student and each | 2,806.619 | 4.681 |
of those dictionaries has two keys name | 2,809.079 | 4.201 |
and house wouldn't it be nice if there | 2,811.3 | 5.1 |
were ran code to tell python sort this | 2,813.28 | 6.12 |
list by looking at this key in each | 2,816.4 | 4.56 |
dictionary because that would give this | 2,819.4 | 4.199 |
the ability to sort either by name or | 2,820.96 | 4.98 |
even by house or even by any other field | 2,823.599 | 5.22 |
that we add to that file so it turns out | 2,825.94 | 5.52 |
we can do this we can tell the sorted | 2,828.819 | 4.8 |
function not just to reverse things or | 2,831.46 | 4.34 |
not it takes another position National | 2,833.619 | 5.341 |
it takes another named parameter called | 2,835.8 | 5.799 |
key where you can specify what key | 2,838.96 | 5.34 |
should be used in order to sort some | 2,841.599 | 4.381 |
list of dictionaries and I'm going to | 2,844.3 | 3.66 |
propose that we do this I'm going to | 2,845.98 | 4.139 |
first Define a function temporarily for | 2,847.96 | 5.099 |
now called get name and this functions | 2,850.119 | 5.581 |
purpose in life given a student is to | 2,853.059 | 5.161 |
quite simply return the student's name | 2,855.7 | 5.1 |
from that particular dictionary so if | 2,858.22 | 4.56 |
student is a dictionary this is going to | 2,860.8 | 4.14 |
return literally the student's name and | 2,862.78 | 4.02 |
that's it that's the sole purpose of | 2,864.94 | 4.679 |
this function in life what do I now want | 2,866.8 | 4.68 |
to do well now that I have a function | 2,869.619 | 4.2 |
that given a student will return to me | 2,871.48 | 4.98 |
the student's name I can do this I can | 2,873.819 | 5.821 |
change sorted to say use a key that's | 2,876.46 | 5.76 |
equal to whatever the return value of | 2,879.64 | 5.28 |
get name is and this now is a feature of | 2,882.22 | 5.639 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.