text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
a variable this time called names plural | 171 | 4.98 |
and set it equal to an empty list recall | 173.4 | 3.839 |
that the square bracket notation | 175.98 | 2.88 |
especially if nothing's inside of it | 177.239 | 4.08 |
just means give me an empty list that we | 178.86 | 4.92 |
can add things to over time well what do | 181.319 | 4.14 |
we want to add to it well let's add | 183.78 | 3.78 |
three names each from the user and let | 185.459 | 4.081 |
me say something like this for | 187.56 | 5.099 |
underscore in range of three let me go | 189.54 | 6 |
ahead and prompt the user with the input | 192.659 | 4.86 |
function and getting their name in this | 195.54 | 5.04 |
variable and then using list syntax I | 197.519 | 7.021 |
can say names dot append name to that | 200.58 | 7.26 |
list and now I have in that list that | 204.54 | 6.059 |
given name one two three of them other | 207.84 | 4.679 |
points to note is I could use a variable | 210.599 | 3.961 |
here like I which is conventional but if | 212.519 | 4.321 |
I'm not actually using I explicitly on | 214.56 | 3.599 |
any subsequent lines I might as well | 216.84 | 3.179 |
just use underscore which is a pythonic | 218.159 | 3.781 |
convention and actually if I want to | 220.019 | 3.661 |
clean this up a little bit right now | 221.94 | 3.9 |
notice that my name variable doesn't | 223.68 | 4.199 |
really need to exist because I'm | 225.84 | 3.3 |
assigning it a value and then | 227.879 | 3.42 |
immediately appending it well I could | 229.14 | 4.26 |
tighten this up further by just getting | 231.299 | 4.981 |
rid of that variable altogether and just | 233.4 | 4.919 |
appending immediately the return value | 236.28 | 4.5 |
of input I think we could go both ways | 238.319 | 4.321 |
in terms of design here on the one hand | 240.78 | 3.179 |
it's a pretty short line and it's | 242.64 | 2.819 |
readable on the other hand if I were to | 243.959 | 3.42 |
eventually change this phrase to be not | 245.459 | 3.721 |
what's your name but something longer we | 247.379 | 3.481 |
might want to break it out again into | 249.18 | 3.18 |
two lines but for now I think it's | 250.86 | 3.84 |
pretty readable now later in the program | 252.36 | 4.2 |
let's just go ahead and print out those | 254.7 | 3.599 |
same names but let's sort them | 256.56 | 4.26 |
alphabetically so that it makes sense to | 258.299 | 4.861 |
be gathering them all together then | 260.82 | 3.9 |
sorting them and printing them so how | 263.16 | 3.36 |
can I do that well in Python the | 264.72 | 3.9 |
simplest way to sort a list in a loop is | 266.52 | 4.32 |
probably to do something like this for | 268.62 | 5.639 |
name in names but wait let's sort the | 270.84 | 4.919 |
names first recall that there's a | 274.259 | 3.481 |
function called sorted which will return | 275.759 | 4.861 |
a sorted version of that list now let's | 277.74 | 5.7 |
go ahead and print out an F string that | 280.62 | 6.12 |
says again hello bracket name close | 283.44 | 5.34 |
quotes all right let me go ahead and run | 286.74 | 5.7 |
this so python of names dot pi and let | 288.78 | 5.639 |
me go ahead and type in a few names this | 292.44 | 3.66 |
time how about Hermione | 294.419 | 5.161 |
how about Harry how about Ron and notice | 296.1 | 5.4 |
that they're not quite in alphabetical | 299.58 | 4.679 |
order but when I hit enter and that Loop | 301.5 | 4.74 |
kicks in it's going to print out hello | 304.259 | 5.22 |
Harry hello Hermione hello Ron in sorted | 306.24 | 4.08 |
order | 309.479 | 2.881 |
but of course now if I run this program | 310.32 | 4.62 |
again all of the names are lost and if | 312.36 | 4.38 |
this is a bigger program than this that | 314.94 | 3.24 |
might actually be pretty painful to have | 316.74 | 3.179 |
to re-input the same information again | 318.18 | 3.9 |
and again and again wouldn't it be nice | 319.919 | 4.381 |
like most any program today on a phone | 322.08 | 4.559 |
or a laptop or desktop or Cloud to be | 324.3 | 5.28 |
able to save this information somehow | 326.639 | 5.701 |
instead and that's where file i o comes | 329.58 | 4.679 |
in and that's where Files come in they | 332.34 | 3.079 |
are a way of storing information | 334.259 | 3.78 |
persistently on your own phone or Mac or | 335.419 | 5.801 |
PC or some Cloud servers disk so that | 338.039 | 4.801 |
they're there when you come back and run | 341.22 | 4.14 |
the program again so how can we go about | 342.84 | 6.24 |
saving all three of these names on in a | 345.36 | 5.7 |
file as opposed to having to type them | 349.08 | 4.38 |
again and again let me go ahead and | 351.06 | 4.02 |
simplify this file and again give myself | 353.46 | 4.079 |
just a single variable called name and | 355.08 | 6 |
set the return value of input equal to | 357.539 | 5.461 |
that variable so what's your name as | 361.08 | 4.739 |
before quote unquote and now let me go | 363 | 4.86 |
ahead and let me do something more with | 365.819 | 4.141 |
this value instead of just adding it to | 367.86 | 3.959 |
a list or printing it immediately out | 369.96 | 3.959 |
let's save the value of the person's | 371.819 | 3.961 |
name that's just been typed in to a file | 373.919 | 3.961 |
well how do we go about doing that well | 375.78 | 3.6 |
in Python there's this function called | 377.88 | 3.42 |
open whose purpose in life is to do just | 379.38 | 4.7 |
that to open a file but to open it up | 381.3 | 4.8 |
programmatically so that you the | 384.08 | 3.64 |
programmer can actually read information | 386.1 | 4.8 |
from it or write information to it so | 387.72 | 4.979 |
open is like the programmer's equivalent | 390.9 | 3.48 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.