text
stringlengths
1
81
start
float64
0
10.1k
duration
float64
0
24.9
and printing it out it's too late to
1,286.52
4.44
sort I really need to read all of the
1,288.98
4.559
lines first without printing them sort
1,290.96
4.5
them then print them so we have to take
1,293.539
3.961
a step back in order to add now now this
1,295.46
4.14
new feature so how can I do this well
1,297.5
4.14
let me combine some ideas from before
1,299.6
4.319
let me go ahead and start fresh with
1,301.64
4.26
this let me give myself a list called
1,303.919
4.681
names and assign it an empty list just
1,305.9
4.5
so I have a variable in which to
1,308.6
4.02
accumulate all of these lines and now
1,310.4
4.86
let me open the file with open quote
1,312.62
4.98
unquote names.txt and it turns out I can
1,315.26
4.02
tighten this up a little bit it turns
1,317.6
3.24
out if you're opening a file to read it
1,319.28
3.72
you don't need to specify quote unquote
1,320.84
4.68
r that is the implicit default so you
1,323
4.02
can tighten things up by just saying
1,325.52
3.24
open names.text and you'll be able to
1,327.02
4.019
read the file but not write it I'm going
1,328.76
4.2
to give myself a variable called file as
1,331.039
4.321
before I am going to iterate over the
1,332.96
4.68
file in the same way for line in file
1,335.36
5.28
but instead of printing each line I'm
1,337.64
5.22
going to do this I'm going to take my
1,340.64
5.1
names list and append to it and this is
1,342.86
5.52
appending to a list in memory not
1,345.74
5.22
appending to the file itself I'm going
1,348.38
4.08
to go ahead and append the current line
1,350.96
3.9
but I'm going to strip off the new line
1,352.46
4.079
at the end so that all I'm adding to
1,354.86
4.52
this list is each of the students names
1,356.539
5.221
now I can use that familiar technique
1,359.38
5.02
from before let me go outside of this
1,361.76
4.32
with statement because now I've read the
1,364.4
3.48
entire file presumably so by the time
1,366.08
4.56
I'm done with lines four and five again
1,367.88
4.26
and again and again for each line in the
1,370.64
3.539
file I'm done with the file it can close
1,372.14
4.14
I now have all of the students names in
1,374.179
5.101
this list variable let me do this for
1,376.28
7.019
name in not just names but the sorted
1,379.28
6.72
names using our python function sorted
1,383.299
5.281
which does just that and do print quote
1,386
5.4
unquote with an F string hello comma and
1,388.58
5.28
now I'll plug in bracket name
1,391.4
5.7
so now what have I done I'm creating a
1,393.86
4.74
list at the beginning just so I have a
1,397.1
3.9
place to gather my data I then on lines
1,398.6
4.26
three through five iterate over the file
1,401
4.26
from top to bottom reading in each line
1,402.86
4.08
one at a time stripping off the new line
1,405.26
3.299
and adding just the student's name to
1,406.94
3.599
this list and the reason I'm doing that
1,408.559
4.98
is so that on line seven I can sort all
1,410.539
4.681
of those names now that they're all in
1,413.539
4.561
memory and print them in order I need to
1,415.22
4.86
load them all into memory before I can
1,418.1
3.84
sort them otherwise I'd be printing them
1,420.08
3.719
out prematurely and Draco would end up
1,421.94
4.14
last instead of first so let me go ahead
1,423.799
4.141
in my terminal window and run python of
1,426.08
5.04
names.pi now and hit enter and there we
1,427.94
6.119
go the same list of four hellos but now
1,431.12
4.919
they're sorted and this is a very common
1,434.059
4.081
technique when dealing with files and
1,436.039
3.721
information more generally if you want
1,438.14
4.26
to change that data in some way like
1,439.76
4.799
sorting it creating some kind of
1,442.4
3.779
variable at the top of your program like
1,444.559
3.72
a list adding or appending information
1,446.179
4.261
to it just to collect it in one place
1,448.279
4.441
and then do something interesting with
1,450.44
4.5
that collection that list is exactly
1,452.72
4.38
what I've done here now I should note
1,454.94
4.14
that if we just want to sort the file we
1,457.1
3.84
can actually do this even more simply in
1,459.08
3.959
Python particularly by not bothering
1,460.94
4.68
with this names list nor the second for
1,463.039
4.14
Loop and let me go ahead and instead
1,465.62
3.539
just do more simply this let me go ahead
1,467.179
3.781
and tell python that we want the file
1,469.159
4.02
itself to be sorted using that same
1,470.96
4.199
sorted function but this time on the
1,473.179
4.201
file itself and then inside of that for
1,475.159
3.721
Loop let's just go ahead and print right
1,477.38
4.26
away our hello comma followed by the
1,478.88
4.679
line itself but still stripping off of
1,481.64
4.68
the end of it any white space therein if
1,483.559
4.261
we go ahead and run this same program
1,486.32
4.02
now with pythonupnames.pi and hit enter
1,487.82
4.26
we get the same result but of course
1,490.34
4.14
it's a lot more compact but for the sake
1,492.08
4.68
of discussion let's assume that we do
1,494.48
4.5
actually want to potentially make some
1,496.76
3.96
changes to the data as we iterate over
1,498.98
3.48
it so let me undo those changes leave
1,500.72
3.72
things as is where by now we'll continue
1,502.46
3.719
to accumulate all of the names first
1,504.44
3.719