text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
alphabetically correct so this function | 3,127.74 | 4.74 |
which you pass just by name you do not | 3,130.2 | 5.1 |
pass in parentheses at the end is called | 3,132.48 | 4.98 |
by the sorted function in order to | 3,135.3 | 5.1 |
figure out for you how to compare these | 3,137.46 | 6.359 |
same values how can we use nested | 3,140.4 | 7.5 |
dictionaries I have read about the | 3,143.819 | 5.821 |
nested dictionaries what is the | 3,147.9 | 3.6 |
difference between nested dictionaries | 3,149.64 | 5.28 |
and the dictionary inside a list I think | 3,151.5 | 5.04 |
it is sure | 3,154.92 | 3.84 |
um uh so we are using a list of | 3,156.54 | 4.26 |
dictionaries why because each of those | 3,158.76 | 3.839 |
dictionaries represents a student and a | 3,160.8 | 3.72 |
student has a name and a house and we | 3,162.599 | 3.361 |
want to I claim maintain that | 3,164.52 | 3.539 |
Association and it's a list of students | 3,165.96 | 3.72 |
because we've got multiple students four | 3,168.059 | 4.5 |
in this case you could create us a | 3,169.68 | 4.379 |
structure that is a dictionary of | 3,172.559 | 3.121 |
dictionaries but I would argue it just | 3,174.059 | 3.3 |
doesn't solve a problem I don't need a | 3,175.68 | 3.179 |
dictionary of dictionary I need a list | 3,177.359 | 4.561 |
of key value pairs right now that's all | 3,178.859 | 5.301 |
so let me propose if we go back to | 3,181.92 | 4.919 |
students.pi here and we revert back to | 3,184.16 | 5.199 |
the approach where we have get name as | 3,186.839 | 5.341 |
the function both used and defined here | 3,189.359 | 4.921 |
and that function Returns the student's | 3,192.18 | 4.679 |
name what happens to be clear is that | 3,194.28 | 5.52 |
the sorted function will use the value | 3,196.859 | 5.941 |
of key get name in this case calling | 3,199.8 | 5.759 |
that function on every dictionary in the | 3,202.8 | 5.46 |
list that it's supposed to soar and that | 3,205.559 | 5.341 |
function get name Returns the string | 3,208.26 | 4.799 |
that sorted will actually use to decide | 3,210.9 | 3.719 |
whether things go in this order left | 3,213.059 | 3.841 |
right or in this order right left it | 3,214.619 | 4.381 |
alphabetizes things based on that return | 3,216.9 | 5.04 |
value so notice that I'm not calling the | 3,219 | 4.8 |
function get name here with parentheses | 3,221.94 | 4.139 |
I'm passing it in only by its name so | 3,223.8 | 5.1 |
that the sorted function can call that | 3,226.079 | 5.581 |
get name function for me now it turns | 3,228.9 | 4.679 |
out as always if you're defining | 3,231.66 | 3.419 |
something be it a variable or in this | 3,233.579 | 3.601 |
case a function and then immediately | 3,235.079 | 5.28 |
using it but never once again needing | 3,237.18 | 5.22 |
the name of that function like get name | 3,240.359 | 4.141 |
we can actually tighten this code up | 3,242.4 | 4.56 |
further I can actually do this I can get | 3,244.5 | 4.26 |
rid of the get name function altogether | 3,246.96 | 4.02 |
just like I could get rid of a variable | 3,248.76 | 4.5 |
that isn't strictly necessary and | 3,250.98 | 4.74 |
instead of passing key the name of a | 3,253.26 | 5.28 |
function I can actually Pass Key what's | 3,255.72 | 5.22 |
called an a Lambda function which is an | 3,258.54 | 4.2 |
anonymous function a function that just | 3,260.94 | 3.899 |
has no name why because you don't need | 3,262.74 | 3.599 |
to give it a name if you're only going | 3,264.839 | 3.72 |
to call it in one place and the syntax | 3,266.339 | 4.141 |
for this in Python is a little weird but | 3,268.559 | 4.56 |
if I do key equals literally the word | 3,270.48 | 5.639 |
Lambda then something like student which | 3,273.119 | 4.801 |
is the name of the parameter I expect | 3,276.119 | 4.081 |
this function to take and then I don't | 3,277.92 | 4.56 |
even type the return key i instead just | 3,280.2 | 5.94 |
say student bracket name so what am I | 3,282.48 | 6.3 |
doing here with my code this code here | 3,286.14 | 5.219 |
that I've highlighted is equivalent to | 3,288.78 | 4.799 |
the get name function I implemented a | 3,291.359 | 4.44 |
moment ago the syntax is admittedly a | 3,293.579 | 4.081 |
little different I don't use def I | 3,295.799 | 3.54 |
didn't even give it a name like get name | 3,297.66 | 3.78 |
i instead I'm using this other keyword | 3,299.339 | 4.5 |
in pi python called Lambda which says | 3,301.44 | 4.619 |
Hey python here comes a function but it | 3,303.839 | 4.74 |
has no name it's Anonymous that function | 3,306.059 | 4.74 |
takes a parameter I could call it | 3,308.579 | 3.961 |
anything I want I'm calling it student | 3,310.799 | 4.741 |
why because this function that's passed | 3,312.54 | 6.299 |
in as key is called on every one of the | 3,315.54 | 5.16 |
students in that list every one of the | 3,318.839 | 4.381 |
dictionaries in that list what do I want | 3,320.7 | 4.619 |
this Anonymous function to return well | 3,323.22 | 4.5 |
given a student I want to index into | 3,325.319 | 4.98 |
that dictionary and access their name so | 3,327.72 | 4.92 |
that the string Hermione and Harry and | 3,330.299 | 4.981 |
Ron and Draco is ultimately returned and | 3,332.64 | 4.62 |
that's what the sorted function uses to | 3,335.28 | 4.5 |
decide how to sort these bigger | 3,337.26 | 4.5 |
dictionaries that have other Keys like | 3,339.78 | 3.72 |
house as well | 3,341.76 | 3.72 |
so if I now go back to my terminal | 3,343.5 | 4.5 |
window and run python of students.pi it | 3,345.48 | 5.22 |
still seems to work the same but it's | 3,348 | 4.38 |
arguably a little better design because | 3,350.7 | 3.599 |
I didn't waste lines of Code by defining | 3,352.38 | 3.66 |
some other function calling it in one | 3,354.299 | 4.32 |
and only one place I've done it all sort | 3,356.04 | 4.98 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.