text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
element because remember we start | 2,181.48 | 4.56 |
indexing at zero in Python and one is | 2,182.92 | 4.98 |
going to be the second second element so | 2,186.04 | 3.78 |
let me go ahead and run this now and see | 2,187.9 | 6.02 |
what happens python of uh | 2,189.82 | 7.92 |
students.pi enter and we see Hermione's | 2,193.92 | 5.32 |
in Gryffindor Harry's and Gryffindor Ron | 2,197.74 | 3.48 |
is in Gryffindor and Draco is in | 2,199.24 | 4.92 |
Slytherin so we have now implemented our | 2,201.22 | 6.06 |
own code from scratch that actually | 2,204.16 | 6.36 |
parses that is reads and interprets a | 2,207.28 | 5.64 |
CSV file ultimately here | 2,210.52 | 4.2 |
now let me pause to see if there's any | 2,212.92 | 3.419 |
questions but we'll make this even | 2,214.72 | 4.2 |
easier to read in just a moment | 2,216.339 | 4.681 |
any questions on what we've just done | 2,218.92 | 4.8 |
here by splitting by comma so my | 2,221.02 | 6.36 |
question is uh can we edit any line of | 2,223.72 | 6.72 |
code anytime we want or uh the only | 2,227.38 | 5.82 |
option that we have is to append uh the | 2,230.44 | 5.82 |
lines or let's say if we want to let's | 2,233.2 | 6.659 |
say change headies uh house to let's say | 2,236.26 | 7.2 |
Slytherin or some other house yeah a | 2,239.859 | 5.22 |
really good question what if you want to | 2,243.46 | 4.44 |
in Python change a line in the file and | 2,245.079 | 5.76 |
not just a pen to the end you would have | 2,247.9 | 4.98 |
to implement that logic yourself so for | 2,250.839 | 4.561 |
instance you could imagine now opening | 2,252.88 | 4.68 |
the file and reading all of the contents | 2,255.4 | 4.679 |
in then maybe iterating over each of | 2,257.56 | 4.26 |
those lines and as soon as you see that | 2,260.079 | 4.141 |
the current name equals equals Harry you | 2,261.82 | 4.44 |
could maybe change his house to | 2,264.22 | 4.44 |
Slytherin and then it would be up to you | 2,266.26 | 4.8 |
though to write all of those changes | 2,268.66 | 4.32 |
back to the file so in that case you | 2,271.06 | 3.96 |
might want to in simplest form read the | 2,272.98 | 4.379 |
file once and let it close then open it | 2,275.02 | 4.5 |
again but open for writing and change | 2,277.359 | 4.681 |
the whole file it's not really possible | 2,279.52 | 4.8 |
or easy to go in and change just part of | 2,282.04 | 4.26 |
the file though you can do it it's | 2,284.32 | 4.019 |
easier to actually read the whole file | 2,286.3 | 3.96 |
make your changes in memory then write | 2,288.339 | 3.961 |
the whole file out but for larger files | 2,290.26 | 4.02 |
where that might be quite slow you can | 2,292.3 | 4.62 |
be more clever than that well let me | 2,294.28 | 4.68 |
propose now that we clean this up a | 2,296.92 | 3.48 |
little bit because I actually think this | 2,298.96 | 3.48 |
is a little cryptic to read Row Bracket | 2,300.4 | 4.199 |
zero Row Bracket one it's it's not that | 2,302.44 | 4.44 |
well written at the moment I would say | 2,304.599 | 5.461 |
but it turns out that when you have a | 2,306.88 | 5.58 |
variable that's a list like row you | 2,310.06 | 3.72 |
don't have to throw all of those | 2,312.46 | 3.42 |
variables into a list you can actually | 2,313.78 | 5.28 |
unpack that whole sequence at once that | 2,315.88 | 4.739 |
is to say if you know that a function | 2,319.06 | 4.26 |
like split returns a list but you know | 2,320.619 | 5.041 |
in advance that it's going to return two | 2,323.32 | 4.56 |
values in a list the first and the | 2,325.66 | 4.08 |
second you don't have to throw them all | 2,327.88 | 3.84 |
into a variable that itself is a list | 2,329.74 | 3.859 |
you can actually unpack them | 2,331.72 | 4.26 |
simultaneously into two variables doing | 2,333.599 | 4.841 |
name comma house so this is a nice | 2,335.98 | 4.619 |
python technique to not only create but | 2,338.44 | 3.26 |
assign | 2,340.599 | 4.441 |
automatically in parallel two variables | 2,341.7 | 5.8 |
at once rather than just one so this | 2,345.04 | 4.079 |
will have the effect of putting the name | 2,347.5 | 3.54 |
in the left Hermione and it will have | 2,349.119 | 3.48 |
the effect of putting Gryffindor the | 2,351.04 | 3.66 |
house in the right variable and we now | 2,352.599 | 4.02 |
no longer have a row we can now make our | 2,354.7 | 3.36 |
code a little more readable by now | 2,356.619 | 3.781 |
literally just saying name down here and | 2,358.06 | 4.5 |
for instance house down here so just a | 2,360.4 | 3.179 |
little more readable even though | 2,362.56 | 4.559 |
functionally the code now is exactly the | 2,363.579 | 4.681 |
same | 2,367.119 | 3.661 |
all right so this now works and I'll | 2,368.26 | 4.2 |
confirm as much by just running it once | 2,370.78 | 4.26 |
more python of students.pi enter and we | 2,372.46 | 5.28 |
see that the text is as intended but | 2,375.04 | 4.44 |
suppose for the sake of discussion that | 2,377.74 | 5.099 |
I'd like to sort this list of output I'd | 2,379.48 | 5.46 |
like to say hello again to Draco first | 2,382.839 | 4.381 |
then hello to Harry then Hermione then | 2,384.94 | 5.04 |
Ron how can I go about doing this well | 2,387.22 | 4.44 |
let's take some inspiration from the | 2,389.98 | 3.119 |
previous example where we're only | 2,391.66 | 4.679 |
dealing with names and instead do it | 2,393.099 | 5.641 |
with these full phrases so and so is | 2,396.339 | 4.26 |
in-house well let me go ahead and do | 2,398.74 | 3.42 |
this I'm going to go ahead and start | 2,400.599 | 4.02 |
scratch and give myself a list called | 2,402.16 | 4.56 |
students equal to an empty list | 2,404.619 | 4.021 |
initially and then with open | 2,406.72 | 4.379 |
students.csv | 2,408.64 | 4.979 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.