[ { "text": "foreign", "start": 1.26, "duration": 11.999 }, { "text": "[Music]", "start": 3.41, "duration": 9.849 }, { "text": "[Music]", "start": 15.28, "duration": 6.869 }, { "text": "this is cs50's Introduction to", "start": 25.34, "duration": 4.48 }, { "text": "programming with python my name is David", "start": 27.96, "duration": 4.439 }, { "text": "Malin and this is our week on file IO", "start": 29.82, "duration": 4.919 }, { "text": "input and output of files so up until", "start": 32.399, "duration": 4.201 }, { "text": "now most every program we've written", "start": 34.739, "duration": 3.84 }, { "text": "just stores all the information that it", "start": 36.6, "duration": 4.56 }, { "text": "collects in memory that is in variables", "start": 38.579, "duration": 4.681 }, { "text": "or inside of the program itself a", "start": 41.16, "duration": 3.54 }, { "text": "downside of which is that as soon as the", "start": 43.26, "duration": 3.24 }, { "text": "program exits anything you typed in", "start": 44.7, "duration": 3.359 }, { "text": "anything that you did with that program", "start": 46.5, "duration": 4.559 }, { "text": "is lost now with files of course on your", "start": 48.059, "duration": 4.921 }, { "text": "Mac or PC you can hang on to information", "start": 51.059, "duration": 4.381 }, { "text": "long term and file i o within the", "start": 52.98, "duration": 3.78 }, { "text": "context of programming is all about", "start": 55.44, "duration": 3.959 }, { "text": "writing code that can read from that is", "start": 56.76, "duration": 5.04 }, { "text": "load information from or write to that", "start": 59.399, "duration": 5.101 }, { "text": "is save information to files themselves", "start": 61.8, "duration": 4.62 }, { "text": "so let's see if we can't transition then", "start": 64.5, "duration": 4.38 }, { "text": "from only using memory and variables and", "start": 66.42, "duration": 4.379 }, { "text": "the like to actually writing code that", "start": 68.88, "duration": 3.599 }, { "text": "saves some files for us and therefore", "start": 70.799, "duration": 4.801 }, { "text": "data persistently well to do this let me", "start": 72.479, "duration": 4.68 }, { "text": "propose that we first consider a", "start": 75.6, "duration": 3.72 }, { "text": "familiar data structure a familiar type", "start": 77.159, "duration": 3.96 }, { "text": "of variable that we've seen before that", "start": 79.32, "duration": 3.839 }, { "text": "of a list and using lists we've been", "start": 81.119, "duration": 4.021 }, { "text": "able to store more than in one piece of", "start": 83.159, "duration": 3.661 }, { "text": "information in the past using one", "start": 85.14, "duration": 3.299 }, { "text": "variable we typically store one value", "start": 86.82, "duration": 3.96 }, { "text": "but if that variable is a list we can", "start": 88.439, "duration": 4.081 }, { "text": "store multiple values unfortunately", "start": 90.78, "duration": 3.6 }, { "text": "lists are stored in the computer's", "start": 92.52, "duration": 4.02 }, { "text": "memory and so once your program exits", "start": 94.38, "duration": 4.26 }, { "text": "even the contents of those disappear but", "start": 96.54, "duration": 3.719 }, { "text": "let's at least give ourselves a starting", "start": 98.64, "duration": 3.96 }, { "text": "point so I'm over here in vs code and", "start": 100.259, "duration": 3.841 }, { "text": "I'm going to go ahead and create a", "start": 102.6, "duration": 4.379 }, { "text": "simple program using Code of names dot", "start": 104.1, "duration": 5.339 }, { "text": "Pi a program that just collects people's", "start": 106.979, "duration": 4.621 }, { "text": "names students names if you will and I'm", "start": 109.439, "duration": 4.14 }, { "text": "going to do it super simply initially in", "start": 111.6, "duration": 3.36 }, { "text": "a manner consistent with what we've done", "start": 113.579, "duration": 3.241 }, { "text": "in the past to get user input and print", "start": 114.96, "duration": 3.42 }, { "text": "it back out I'm going to say something", "start": 116.82, "duration": 4.74 }, { "text": "like this name equals input quote", "start": 118.38, "duration": 6.059 }, { "text": "unquote what's your name thereby storing", "start": 121.56, "duration": 5.339 }, { "text": "in a variable called name the return", "start": 124.439, "duration": 5.221 }, { "text": "value of input as always and as always", "start": 126.899, "duration": 4.2 }, { "text": "I'm going to go ahead and very simply", "start": 129.66, "duration": 3.36 }, { "text": "print out a nice F string that says", "start": 131.099, "duration": 4.321 }, { "text": "hello comma and then in curly brace's", "start": 133.02, "duration": 4.32 }, { "text": "name to print out hello David hello", "start": 135.42, "duration": 4.26 }, { "text": "world however happens to be using the", "start": 137.34, "duration": 3.899 }, { "text": "program let me go ahead and run this", "start": 139.68, "duration": 3.0 }, { "text": "just to remind myself what I should", "start": 141.239, "duration": 3.841 }, { "text": "expect and if I run python names.pi and", "start": 142.68, "duration": 4.38 }, { "text": "hit enter type in my name like David of", "start": 145.08, "duration": 4.739 }, { "text": "course I now see hello comma David so", "start": 147.06, "duration": 4.38 }, { "text": "suppose though that we wanted to add", "start": 149.819, "duration": 3.301 }, { "text": "support not just for one name but", "start": 151.44, "duration": 3.72 }, { "text": "multiple names maybe three names for the", "start": 153.12, "duration": 3.479 }, { "text": "sake of discussion so that we can begin", "start": 155.16, "duration": 4.26 }, { "text": "to accumulate some amount of information", "start": 156.599, "duration": 5.161 }, { "text": "in the program such that it's really", "start": 159.42, "duration": 4.2 }, { "text": "going to be a downside if we keep", "start": 161.76, "duration": 4.44 }, { "text": "throwing it away once the program exits", "start": 163.62, "duration": 5.1 }, { "text": "well let me go back into names.pi up", "start": 166.2, "duration": 4.8 }, { "text": "here atub let me proactively give myself", "start": 168.72, "duration": 4.68 }, { "text": "a variable this time called names plural", "start": 171.0, "duration": 4.98 }, { "text": "and set it equal to an empty list recall", "start": 173.4, "duration": 3.839 }, { "text": "that the square bracket notation", "start": 175.98, "duration": 2.88 }, { "text": "especially if nothing's inside of it", "start": 177.239, "duration": 4.08 }, { "text": "just means give me an empty list that we", "start": 178.86, "duration": 4.92 }, { "text": "can add things to over time well what do", "start": 181.319, "duration": 4.14 }, { "text": "we want to add to it well let's add", "start": 183.78, "duration": 3.78 }, { "text": "three names each from the user and let", "start": 185.459, "duration": 4.081 }, { "text": "me say something like this for", "start": 187.56, "duration": 5.099 }, { "text": "underscore in range of three let me go", "start": 189.54, "duration": 6.0 }, { "text": "ahead and prompt the user with the input", "start": 192.659, "duration": 4.86 }, { "text": "function and getting their name in this", "start": 195.54, "duration": 5.04 }, { "text": "variable and then using list syntax I", "start": 197.519, "duration": 7.021 }, { "text": "can say names dot append name to that", "start": 200.58, "duration": 7.26 }, { "text": "list and now I have in that list that", "start": 204.54, "duration": 6.059 }, { "text": "given name one two three of them other", "start": 207.84, "duration": 4.679 }, { "text": "points to note is I could use a variable", "start": 210.599, "duration": 3.961 }, { "text": "here like I which is conventional but if", "start": 212.519, "duration": 4.321 }, { "text": "I'm not actually using I explicitly on", "start": 214.56, "duration": 3.599 }, { "text": "any subsequent lines I might as well", "start": 216.84, "duration": 3.179 }, { "text": "just use underscore which is a pythonic", "start": 218.159, "duration": 3.781 }, { "text": "convention and actually if I want to", "start": 220.019, "duration": 3.661 }, { "text": "clean this up a little bit right now", "start": 221.94, "duration": 3.9 }, { "text": "notice that my name variable doesn't", "start": 223.68, "duration": 4.199 }, { "text": "really need to exist because I'm", "start": 225.84, "duration": 3.3 }, { "text": "assigning it a value and then", "start": 227.879, "duration": 3.42 }, { "text": "immediately appending it well I could", "start": 229.14, "duration": 4.26 }, { "text": "tighten this up further by just getting", "start": 231.299, "duration": 4.981 }, { "text": "rid of that variable altogether and just", "start": 233.4, "duration": 4.919 }, { "text": "appending immediately the return value", "start": 236.28, "duration": 4.5 }, { "text": "of input I think we could go both ways", "start": 238.319, "duration": 4.321 }, { "text": "in terms of design here on the one hand", "start": 240.78, "duration": 3.179 }, { "text": "it's a pretty short line and it's", "start": 242.64, "duration": 2.819 }, { "text": "readable on the other hand if I were to", "start": 243.959, "duration": 3.42 }, { "text": "eventually change this phrase to be not", "start": 245.459, "duration": 3.721 }, { "text": "what's your name but something longer we", "start": 247.379, "duration": 3.481 }, { "text": "might want to break it out again into", "start": 249.18, "duration": 3.18 }, { "text": "two lines but for now I think it's", "start": 250.86, "duration": 3.84 }, { "text": "pretty readable now later in the program", "start": 252.36, "duration": 4.2 }, { "text": "let's just go ahead and print out those", "start": 254.7, "duration": 3.599 }, { "text": "same names but let's sort them", "start": 256.56, "duration": 4.26 }, { "text": "alphabetically so that it makes sense to", "start": 258.299, "duration": 4.861 }, { "text": "be gathering them all together then", "start": 260.82, "duration": 3.9 }, { "text": "sorting them and printing them so how", "start": 263.16, "duration": 3.36 }, { "text": "can I do that well in Python the", "start": 264.72, "duration": 3.9 }, { "text": "simplest way to sort a list in a loop is", "start": 266.52, "duration": 4.32 }, { "text": "probably to do something like this for", "start": 268.62, "duration": 5.639 }, { "text": "name in names but wait let's sort the", "start": 270.84, "duration": 4.919 }, { "text": "names first recall that there's a", "start": 274.259, "duration": 3.481 }, { "text": "function called sorted which will return", "start": 275.759, "duration": 4.861 }, { "text": "a sorted version of that list now let's", "start": 277.74, "duration": 5.7 }, { "text": "go ahead and print out an F string that", "start": 280.62, "duration": 6.12 }, { "text": "says again hello bracket name close", "start": 283.44, "duration": 5.34 }, { "text": "quotes all right let me go ahead and run", "start": 286.74, "duration": 5.7 }, { "text": "this so python of names dot pi and let", "start": 288.78, "duration": 5.639 }, { "text": "me go ahead and type in a few names this", "start": 292.44, "duration": 3.66 }, { "text": "time how about Hermione", "start": 294.419, "duration": 5.161 }, { "text": "how about Harry how about Ron and notice", "start": 296.1, "duration": 5.4 }, { "text": "that they're not quite in alphabetical", "start": 299.58, "duration": 4.679 }, { "text": "order but when I hit enter and that Loop", "start": 301.5, "duration": 4.74 }, { "text": "kicks in it's going to print out hello", "start": 304.259, "duration": 5.22 }, { "text": "Harry hello Hermione hello Ron in sorted", "start": 306.24, "duration": 4.08 }, { "text": "order", "start": 309.479, "duration": 2.881 }, { "text": "but of course now if I run this program", "start": 310.32, "duration": 4.62 }, { "text": "again all of the names are lost and if", "start": 312.36, "duration": 4.38 }, { "text": "this is a bigger program than this that", "start": 314.94, "duration": 3.24 }, { "text": "might actually be pretty painful to have", "start": 316.74, "duration": 3.179 }, { "text": "to re-input the same information again", "start": 318.18, "duration": 3.9 }, { "text": "and again and again wouldn't it be nice", "start": 319.919, "duration": 4.381 }, { "text": "like most any program today on a phone", "start": 322.08, "duration": 4.559 }, { "text": "or a laptop or desktop or Cloud to be", "start": 324.3, "duration": 5.28 }, { "text": "able to save this information somehow", "start": 326.639, "duration": 5.701 }, { "text": "instead and that's where file i o comes", "start": 329.58, "duration": 4.679 }, { "text": "in and that's where Files come in they", "start": 332.34, "duration": 3.079 }, { "text": "are a way of storing information", "start": 334.259, "duration": 3.78 }, { "text": "persistently on your own phone or Mac or", "start": 335.419, "duration": 5.801 }, { "text": "PC or some Cloud servers disk so that", "start": 338.039, "duration": 4.801 }, { "text": "they're there when you come back and run", "start": 341.22, "duration": 4.14 }, { "text": "the program again so how can we go about", "start": 342.84, "duration": 6.24 }, { "text": "saving all three of these names on in a", "start": 345.36, "duration": 5.7 }, { "text": "file as opposed to having to type them", "start": 349.08, "duration": 4.38 }, { "text": "again and again let me go ahead and", "start": 351.06, "duration": 4.02 }, { "text": "simplify this file and again give myself", "start": 353.46, "duration": 4.079 }, { "text": "just a single variable called name and", "start": 355.08, "duration": 6.0 }, { "text": "set the return value of input equal to", "start": 357.539, "duration": 5.461 }, { "text": "that variable so what's your name as", "start": 361.08, "duration": 4.739 }, { "text": "before quote unquote and now let me go", "start": 363.0, "duration": 4.86 }, { "text": "ahead and let me do something more with", "start": 365.819, "duration": 4.141 }, { "text": "this value instead of just adding it to", "start": 367.86, "duration": 3.959 }, { "text": "a list or printing it immediately out", "start": 369.96, "duration": 3.959 }, { "text": "let's save the value of the person's", "start": 371.819, "duration": 3.961 }, { "text": "name that's just been typed in to a file", "start": 373.919, "duration": 3.961 }, { "text": "well how do we go about doing that well", "start": 375.78, "duration": 3.6 }, { "text": "in Python there's this function called", "start": 377.88, "duration": 3.42 }, { "text": "open whose purpose in life is to do just", "start": 379.38, "duration": 4.7 }, { "text": "that to open a file but to open it up", "start": 381.3, "duration": 4.8 }, { "text": "programmatically so that you the", "start": 384.08, "duration": 3.64 }, { "text": "programmer can actually read information", "start": 386.1, "duration": 4.8 }, { "text": "from it or write information to it so", "start": 387.72, "duration": 4.979 }, { "text": "open is like the programmer's equivalent", "start": 390.9, "duration": 3.48 }, { "text": "of like double clicking on an icon on", "start": 392.699, "duration": 4.261 }, { "text": "your Mac or PC but it's a programmer's", "start": 394.38, "duration": 3.9 }, { "text": "technique because it's going to allow", "start": 396.96, "duration": 3.299 }, { "text": "you to specify exactly what you want to", "start": 398.28, "duration": 5.1 }, { "text": "read from or write to that file formally", "start": 400.259, "duration": 5.461 }, { "text": "its documentation is here and you'll see", "start": 403.38, "duration": 4.02 }, { "text": "that its usage is relatively", "start": 405.72, "duration": 3.06 }, { "text": "straightforward it minimally just", "start": 407.4, "duration": 3.0 }, { "text": "requires the name of the file that we", "start": 408.78, "duration": 4.02 }, { "text": "want to open and optionally how we want", "start": 410.4, "duration": 4.68 }, { "text": "to open it so let me go back to vs code", "start": 412.8, "duration": 4.38 }, { "text": "here and let me propose now that I do", "start": 415.08, "duration": 4.26 }, { "text": "this I'm going to go ahead and call this", "start": 417.18, "duration": 4.5 }, { "text": "function called open passing in an", "start": 419.34, "duration": 4.919 }, { "text": "argument for names.txt which is the name", "start": 421.68, "duration": 4.919 }, { "text": "of the file I would like to store all of", "start": 424.259, "duration": 4.021 }, { "text": "these names in I could call it anything", "start": 426.599, "duration": 3.241 }, { "text": "I want but because it's going to be just", "start": 428.28, "duration": 3.56 }, { "text": "text it's conventional to call it", "start": 429.84, "duration": 4.74 }, { "text": "something.txt but I'm also going to tell", "start": 431.84, "duration": 5.079 }, { "text": "the open function that I plan to write", "start": 434.58, "duration": 4.92 }, { "text": "to this file so as a second argument to", "start": 436.919, "duration": 4.201 }, { "text": "open I'm going to put literally quote", "start": 439.5, "duration": 4.319 }, { "text": "unquote W for right and that's going to", "start": 441.12, "duration": 4.859 }, { "text": "tell open to open the file in a way", "start": 443.819, "duration": 3.841 }, { "text": "that's going to allow me to change the", "start": 445.979, "duration": 3.06 }, { "text": "contents and better yet if it doesn't", "start": 447.66, "duration": 3.42 }, { "text": "even exist yet it's going to create the", "start": 449.039, "duration": 4.801 }, { "text": "file for me now open returns what's", "start": 451.08, "duration": 5.339 }, { "text": "called a file handle a special value", "start": 453.84, "duration": 4.32 }, { "text": "that allows me to access that file", "start": 456.419, "duration": 3.361 }, { "text": "subsequently so I'm going to go ahead", "start": 458.16, "duration": 3.479 }, { "text": "and sign it equal to a variable like", "start": 459.78, "duration": 4.38 }, { "text": "file and now I'm going to go ahead and", "start": 461.639, "duration": 5.161 }, { "text": "quite simply write this person's name to", "start": 464.16, "duration": 4.86 }, { "text": "that file so I'm going to literally type", "start": 466.8, "duration": 5.88 }, { "text": "file which is the variable a linking to", "start": 469.02, "duration": 6.42 }, { "text": "that file dot write which is a function", "start": 472.68, "duration": 4.56 }, { "text": "otherwise known as a method that comes", "start": 475.44, "duration": 4.14 }, { "text": "with open files that allows me to write", "start": 477.24, "duration": 5.04 }, { "text": "that name to the file and then lastly", "start": 479.58, "duration": 4.2 }, { "text": "I'm going to quite simply going to go", "start": 482.28, "duration": 3.359 }, { "text": "ahead and say file Dot close which will", "start": 483.78, "duration": 4.68 }, { "text": "close and effectively save the file so", "start": 485.639, "duration": 4.201 }, { "text": "these three lines of code here are", "start": 488.46, "duration": 2.82 }, { "text": "essentially the programmers equivalent", "start": 489.84, "duration": 3.18 }, { "text": "to like double clicking an icon on your", "start": 491.28, "duration": 3.84 }, { "text": "Mac or PC making some changes in", "start": 493.02, "duration": 3.84 }, { "text": "Microsoft Word or some other program and", "start": 495.12, "duration": 3.72 }, { "text": "going to file save we're doing that all", "start": 496.86, "duration": 4.32 }, { "text": "in code with just these three lines here", "start": 498.84, "duration": 5.699 }, { "text": "well let's see now how this works let me", "start": 501.18, "duration": 7.859 }, { "text": "go ahead now and run python of names.pi", "start": 504.539, "duration": 7.56 }, { "text": "and enter let's type in a name I'll type", "start": 509.039, "duration": 4.8 }, { "text": "in Hermione", "start": 512.099, "duration": 5.161 }, { "text": "enter all right where did she end up", "start": 513.839, "duration": 5.82 }, { "text": "well let me go ahead now and type code", "start": 517.26, "duration": 5.519 }, { "text": "of names.txt which is a file that", "start": 519.659, "duration": 5.521 }, { "text": "happens now to exist because I opened it", "start": 522.779, "duration": 4.441 }, { "text": "in right mode and if I open this in a", "start": 525.18, "duration": 4.92 }, { "text": "tab we'll see there's Hermione well", "start": 527.22, "duration": 4.92 }, { "text": "let's go ahead and run names.pi once", "start": 530.1, "duration": 3.72 }, { "text": "more I'm going to go ahead and run", "start": 532.14, "duration": 5.1 }, { "text": "python of names.pi enter and this time", "start": 533.82, "duration": 5.639 }, { "text": "I'll type in Harry let me go ahead and", "start": 537.24, "duration": 3.96 }, { "text": "run it one more time and this time I'll", "start": 539.459, "duration": 4.5 }, { "text": "type in Ron and now let me go up to", "start": 541.2, "duration": 5.579 }, { "text": "names.text where hopefully I'll see all", "start": 543.959, "duration": 4.56 }, { "text": "three of them here", "start": 546.779, "duration": 5.521 }, { "text": "but no I've just actually seen Ron", "start": 548.519, "duration": 6.361 }, { "text": "What might explain what happened to", "start": 552.3, "duration": 4.5 }, { "text": "Hermione and Harry even though I'm", "start": 554.88, "duration": 3.84 }, { "text": "pretty sure I ran the program three", "start": 556.8, "duration": 3.719 }, { "text": "times and I definitely wrote the code", "start": 558.72, "duration": 5.4 }, { "text": "that writes their name to that file", "start": 560.519, "duration": 6.241 }, { "text": "what's going on here do you think I", "start": 564.12, "duration": 4.38 }, { "text": "think because we're not appending them", "start": 566.76, "duration": 4.56 }, { "text": "we should append the names since we are", "start": 568.5, "duration": 5.399 }, { "text": "writing directly it is erasing the old", "start": 571.32, "duration": 4.98 }, { "text": "content and it is replacing with the", "start": 573.899, "duration": 4.861 }, { "text": "last uh", "start": 576.3, "duration": 4.5 }, { "text": "set of characters that we mentioned", "start": 578.76, "duration": 4.86 }, { "text": "exactly unfortunately quote unquote W is", "start": 580.8, "duration": 4.26 }, { "text": "a little dangerous not only will it", "start": 583.62, "duration": 3.24 }, { "text": "create the file for you it will also", "start": 585.06, "duration": 4.26 }, { "text": "recreate the file for you every time you", "start": 586.86, "duration": 4.2 }, { "text": "open the file in that mode so if you", "start": 589.32, "duration": 3.48 }, { "text": "open the file once and write Hermione", "start": 591.06, "duration": 3.719 }, { "text": "that worked just fine as we saw but if", "start": 592.8, "duration": 3.42 }, { "text": "you do it again for Harry if you do it", "start": 594.779, "duration": 3.481 }, { "text": "again for Ron the code is working but", "start": 596.22, "duration": 3.78 }, { "text": "each time it's opening the file and", "start": 598.26, "duration": 4.319 }, { "text": "recreating it with brand new contents so", "start": 600.0, "duration": 4.32 }, { "text": "we had one version with Hermione one", "start": 602.579, "duration": 3.301 }, { "text": "version with Harry and one final version", "start": 604.32, "duration": 3.84 }, { "text": "with Ron but ideally I think we probably", "start": 605.88, "duration": 4.86 }, { "text": "want to be appending as bashal says each", "start": 608.16, "duration": 4.44 }, { "text": "of those names to the file not just", "start": 610.74, "duration": 4.14 }, { "text": "clobbering that is overwriting the file", "start": 612.6, "duration": 4.08 }, { "text": "each time so how can I do this it's", "start": 614.88, "duration": 4.26 }, { "text": "actually a relatively easy fix let me go", "start": 616.68, "duration": 4.14 }, { "text": "ahead and do this as follows I'm going", "start": 619.14, "duration": 3.42 }, { "text": "to first remove the old version of", "start": 620.82, "duration": 4.139 }, { "text": "names.text and now I'm going to change", "start": 622.56, "duration": 4.62 }, { "text": "my code to do this I'm going to change", "start": 624.959, "duration": 5.221 }, { "text": "the W quote unquote to just a quote", "start": 627.18, "duration": 5.219 }, { "text": "unquote a for append which means to add", "start": 630.18, "duration": 3.599 }, { "text": "to the bottom to the bottom to the", "start": 632.399, "duration": 3.421 }, { "text": "bottom again and again now let me go", "start": 633.779, "duration": 4.921 }, { "text": "ahead and rerun python of names.pi and", "start": 635.82, "duration": 5.519 }, { "text": "enter I'll again start from scratch with", "start": 638.7, "duration": 4.5 }, { "text": "Hermione because I'm creating the file", "start": 641.339, "duration": 5.841 }, { "text": "new notice that if I now do code of", "start": 643.2, "duration": 7.379 }, { "text": "names.txt enter we do see that Hermione", "start": 647.18, "duration": 5.98 }, { "text": "is back so we've after removing the file", "start": 650.579, "duration": 4.561 }, { "text": "it did get recreated even though I'm", "start": 653.16, "duration": 4.08 }, { "text": "using append which is good but now let's", "start": 655.14, "duration": 4.74 }, { "text": "see what happens when I go back to my", "start": 657.24, "duration": 4.68 }, { "text": "terminal and this time I run python of", "start": 659.88, "duration": 4.56 }, { "text": "names.pi again this time typing in Harry", "start": 661.92, "duration": 5.039 }, { "text": "and let me run it one more time this", "start": 664.44, "duration": 4.62 }, { "text": "time typing in Ron so hopefully this", "start": 666.959, "duration": 4.021 }, { "text": "time in that second tab names.text I", "start": 669.06, "duration": 4.56 }, { "text": "should now see all three of them but but", "start": 670.98, "duration": 6.539 }, { "text": "but but this doesn't look ideal what", "start": 673.62, "duration": 6.42 }, { "text": "have I clearly done wrong", "start": 677.519, "duration": 3.601 }, { "text": "foreign", "start": 680.04, "duration": 3.06 }, { "text": "something tells me even though all three", "start": 681.12, "duration": 3.36 }, { "text": "names are there it's not going to be", "start": 683.1, "duration": 3.54 }, { "text": "easy to read those back unless you know", "start": 684.48, "duration": 5.34 }, { "text": "where each name ends and Begins the", "start": 686.64, "duration": 6.36 }, { "text": "English form it's not correctly", "start": 689.82, "duration": 5.639 }, { "text": "the English format is not correct like", "start": 693.0, "duration": 5.459 }, { "text": "it's a correct it's concatenating them", "start": 695.459, "duration": 6.541 }, { "text": "it is it's it can it's well it appears", "start": 698.459, "duration": 5.461 }, { "text": "to be concatenating but technically", "start": 702.0, "duration": 4.14 }, { "text": "speaking it's just appending to the file", "start": 703.92, "duration": 5.039 }, { "text": "first Hermione then Harry then Ron it", "start": 706.14, "duration": 4.439 }, { "text": "has the effect of combining them back to", "start": 708.959, "duration": 3.241 }, { "text": "back but it's not concatenating per se", "start": 710.579, "duration": 3.781 }, { "text": "it really is just a pending let's go to", "start": 712.2, "duration": 4.74 }, { "text": "another hand here what really have I", "start": 714.36, "duration": 5.4 }, { "text": "done wrong or equivalently how might I", "start": 716.94, "duration": 3.899 }, { "text": "fix", "start": 719.76, "duration": 3.78 }, { "text": "it would be nice if there were some kind", "start": 720.839, "duration": 4.5 }, { "text": "of gaps between each of the names so we", "start": 723.54, "duration": 5.28 }, { "text": "could read them more cleanly Hello uh we", "start": 725.339, "duration": 7.021 }, { "text": "should add a new line before we write", "start": 728.82, "duration": 6.12 }, { "text": "new name good we want to add a new line", "start": 732.36, "duration": 4.44 }, { "text": "ourselves so whereas print by default", "start": 734.94, "duration": 4.68 }, { "text": "recall always outputs automatically a", "start": 736.8, "duration": 4.68 }, { "text": "line ending of backslash n unless we", "start": 739.62, "duration": 3.779 }, { "text": "override it with the named parameter", "start": 741.48, "duration": 4.32 }, { "text": "called end write does not do that right", "start": 743.399, "duration": 4.44 }, { "text": "takes you literally and if you say right", "start": 745.8, "duration": 4.2 }, { "text": "Hermione that's it you're getting the H", "start": 747.839, "duration": 4.321 }, { "text": "through the E if you say right Harry you", "start": 750.0, "duration": 4.44 }, { "text": "get the H through the uh y you don't get", "start": 752.16, "duration": 5.16 }, { "text": "any extra new lines automatically so if", "start": 754.44, "duration": 5.22 }, { "text": "you want to have a new line at the end", "start": 757.32, "duration": 4.019 }, { "text": "of each of these names we've got to do", "start": 759.66, "duration": 3.299 }, { "text": "that manually so let me again close", "start": 761.339, "duration": 4.261 }, { "text": "names.txt and let me remove the current", "start": 762.959, "duration": 4.861 }, { "text": "file and let me go back up to my code", "start": 765.6, "duration": 3.96 }, { "text": "here and I can fix this in any number of", "start": 767.82, "duration": 2.94 }, { "text": "ways but I'm just going to go ahead and", "start": 769.56, "duration": 3.3 }, { "text": "do this I'm going to write out an F", "start": 770.76, "duration": 4.92 }, { "text": "string that contains name and backslash", "start": 772.86, "duration": 4.56 }, { "text": "n at the end we could do this in", "start": 775.68, "duration": 3.3 }, { "text": "different ways we could manually print", "start": 777.42, "duration": 3.06 }, { "text": "just the new line or some other", "start": 778.98, "duration": 3.18 }, { "text": "technique week but I'm going to go ahead", "start": 780.48, "duration": 3.479 }, { "text": "and use my f strings as I'm in the habit", "start": 782.16, "duration": 3.54 }, { "text": "of doing and just print to the name and", "start": 783.959, "duration": 3.901 }, { "text": "the new line all at once I'm going to go", "start": 785.7, "duration": 3.72 }, { "text": "ahead now and down to my terminal window", "start": 787.86, "duration": 4.08 }, { "text": "run python of names dot Pi again enter", "start": 789.42, "duration": 4.979 }, { "text": "we'll type in Hermione I'm going to run", "start": 791.94, "duration": 4.56 }, { "text": "it again type in Harry I'm going to type", "start": 794.399, "duration": 4.861 }, { "text": "it again and this time Ron now I'm going", "start": 796.5, "duration": 5.579 }, { "text": "to run code of names.txt and open that", "start": 799.26, "duration": 6.06 }, { "text": "file and now it looks like the file is a", "start": 802.079, "duration": 4.801 }, { "text": "bit cleaner indeed I have each of the", "start": 805.32, "duration": 3.9 }, { "text": "name on its own line as well as a line", "start": 806.88, "duration": 4.86 }, { "text": "ending which ensures that we can", "start": 809.22, "duration": 5.28 }, { "text": "separate one from the other now if I", "start": 811.74, "duration": 5.219 }, { "text": "were you know writing code I bet I could", "start": 814.5, "duration": 4.62 }, { "text": "parse that is read the previous file by", "start": 816.959, "duration": 3.841 }, { "text": "looking at differences between lowercase", "start": 819.12, "duration": 3.12 }, { "text": "and uppercase letters but that's going", "start": 820.8, "duration": 3.479 }, { "text": "to get messy quickly generally speaking", "start": 822.24, "duration": 4.32 }, { "text": "when storing data long term in a file", "start": 824.279, "duration": 3.841 }, { "text": "you should probably do it somehow", "start": 826.56, "duration": 3.959 }, { "text": "cleanly like doing one name at a time", "start": 828.12, "duration": 4.74 }, { "text": "well let's now go back and I'll propose", "start": 830.519, "duration": 3.841 }, { "text": "that this code is now working correctly", "start": 832.86, "duration": 3.18 }, { "text": "but we can design it a little bit better", "start": 834.36, "duration": 4.26 }, { "text": "it turns out that it's all too easy when", "start": 836.04, "duration": 4.5 }, { "text": "writing code to sometimes forget to", "start": 838.62, "duration": 4.2 }, { "text": "close files and sometimes this isn't", "start": 840.54, "duration": 4.08 }, { "text": "necessarily a big deal but sometimes it", "start": 842.82, "duration": 3.36 }, { "text": "can create problems files could get", "start": 844.62, "duration": 3.48 }, { "text": "corrupted or accidentally deleted or the", "start": 846.18, "duration": 3.3 }, { "text": "liked depending on what happens in your", "start": 848.1, "duration": 3.12 }, { "text": "code so it turns out that you don't", "start": 849.48, "duration": 4.56 }, { "text": "strictly need to call close on the file", "start": 851.22, "duration": 4.679 }, { "text": "yourself if you take another approach", "start": 854.04, "duration": 5.7 }, { "text": "instead more pythonic when manipulating", "start": 855.899, "duration": 7.081 }, { "text": "files is to do this to introduce this", "start": 859.74, "duration": 6.06 }, { "text": "other keyword called quite simply with", "start": 862.98, "duration": 5.52 }, { "text": "that allows you to specify that in this", "start": 865.8, "duration": 5.039 }, { "text": "context I want you to open and", "start": 868.5, "duration": 5.1 }, { "text": "automatically close some file so how do", "start": 870.839, "duration": 4.921 }, { "text": "we use with it simply looks like this", "start": 873.6, "duration": 4.14 }, { "text": "let me go back to my code here I've", "start": 875.76, "duration": 4.199 }, { "text": "gotten rid of the close line and I'm now", "start": 877.74, "duration": 4.14 }, { "text": "just going to say this instead instead", "start": 879.959, "duration": 4.56 }, { "text": "of saying file equals open I'm going to", "start": 881.88, "duration": 6.0 }, { "text": "say with open then the same arguments as", "start": 884.519, "duration": 5.521 }, { "text": "before and somewhat curiously I'm going", "start": 887.88, "duration": 3.84 }, { "text": "to put the variable at the end of the", "start": 890.04, "duration": 3.72 }, { "text": "line why that's just the way this is", "start": 891.72, "duration": 4.44 }, { "text": "done you say with you call the function", "start": 893.76, "duration": 4.74 }, { "text": "in question and then you say as and", "start": 896.16, "duration": 4.02 }, { "text": "specify the name of the variable that", "start": 898.5, "duration": 3.54 }, { "text": "should be assigned find the return value", "start": 900.18, "duration": 3.959 }, { "text": "of open then I'm going to go ahead and", "start": 902.04, "duration": 4.5 }, { "text": "indent the line underneath so that the", "start": 904.139, "duration": 4.44 }, { "text": "line of code that's writing the name is", "start": 906.54, "duration": 4.2 }, { "text": "now in the context of this with", "start": 908.579, "duration": 4.32 }, { "text": "statement which just ensures that", "start": 910.74, "duration": 4.5 }, { "text": "automatically if I had more code in this", "start": 912.899, "duration": 5.221 }, { "text": "file down below no longer indented the", "start": 915.24, "duration": 4.98 }, { "text": "file would be automatically closed as", "start": 918.12, "duration": 4.44 }, { "text": "soon as line 4 is done executing so it", "start": 920.22, "duration": 3.72 }, { "text": "doesn't change what has just happened", "start": 922.56, "duration": 3.18 }, { "text": "but it does automate the process of at", "start": 923.94, "duration": 3.48 }, { "text": "least closing things for us just to", "start": 925.74, "duration": 3.0 }, { "text": "ensure I don't forget and so that", "start": 927.42, "duration": 4.08 }, { "text": "something doesn't go wrong", "start": 928.74, "duration": 5.58 }, { "text": "but suppose now that I wanted to read", "start": 931.5, "duration": 4.8 }, { "text": "these names from the file all I've done", "start": 934.32, "duration": 3.6 }, { "text": "thus far is write code that writes names", "start": 936.3, "duration": 3.659 }, { "text": "to the file but let's assume now that we", "start": 937.92, "duration": 3.96 }, { "text": "have all of these names in the file and", "start": 939.959, "duration": 4.081 }, { "text": "heck let's go ahead and add one more let", "start": 941.88, "duration": 3.78 }, { "text": "me go ahead and run this one more time", "start": 944.04, "duration": 4.32 }, { "text": "python of names.pi and let's add in", "start": 945.66, "duration": 5.099 }, { "text": "Draco to the mix so now that we have all", "start": 948.36, "duration": 4.56 }, { "text": "four of these names here how might we", "start": 950.759, "duration": 4.5 }, { "text": "want to read them back well let me", "start": 952.92, "duration": 4.56 }, { "text": "propose that we go into names.pi now or", "start": 955.259, "duration": 3.181 }, { "text": "we could create another program", "start": 957.48, "duration": 2.76 }, { "text": "altogether but I'm going to keep reusing", "start": 958.44, "duration": 3.72 }, { "text": "the same name just to keep us focused on", "start": 960.24, "duration": 3.779 }, { "text": "this and now I'm going to write code", "start": 962.16, "duration": 4.919 }, { "text": "that reads an existing file with", "start": 964.019, "duration": 6.18 }, { "text": "Hermione Harry Ron and Draco together", "start": 967.079, "duration": 5.341 }, { "text": "and how do I do this well it's similar", "start": 970.199, "duration": 3.961 }, { "text": "in spirit I'm going to start this time", "start": 972.42, "duration": 4.44 }, { "text": "with with open and then the first", "start": 974.16, "duration": 3.9 }, { "text": "argument is going to be the name of the", "start": 976.86, "duration": 3.599 }, { "text": "file that I want to open as before and", "start": 978.06, "duration": 4.26 }, { "text": "I'm going to open it this time in read", "start": 980.459, "duration": 4.201 }, { "text": "mode quote unquote R and to read a file", "start": 982.32, "duration": 5.519 }, { "text": "just means to load it not to save it and", "start": 984.66, "duration": 5.64 }, { "text": "I'm going to name the return value file", "start": 987.839, "duration": 4.141 }, { "text": "and now I'm going to do this yes and", "start": 990.3, "duration": 3.0 }, { "text": "there's a number of ways I can do this", "start": 991.98, "duration": 3.24 }, { "text": "but one way to read all of the lines", "start": 993.3, "duration": 4.14 }, { "text": "from the file at once would be this let", "start": 995.22, "duration": 4.44 }, { "text": "me declare a variable called lines let", "start": 997.44, "duration": 4.44 }, { "text": "me access that file and call a function", "start": 999.66, "duration": 4.02 }, { "text": "or a method that comes with it called", "start": 1001.88, "duration": 3.66 }, { "text": "read lines so if you read the", "start": 1003.68, "duration": 4.079 }, { "text": "documentation on file i o and python", "start": 1005.54, "duration": 4.5 }, { "text": "you'll see that open files come with a", "start": 1007.759, "duration": 4.2 }, { "text": "special method whose purpose in life is", "start": 1010.04, "duration": 4.38 }, { "text": "to read all the lines from the file and", "start": 1011.959, "duration": 5.221 }, { "text": "return them to me as a list so what this", "start": 1014.42, "duration": 4.8 }, { "text": "line 2 is doing is it's reading all of", "start": 1017.18, "duration": 4.32 }, { "text": "the lines from that file storing them in", "start": 1019.22, "duration": 5.099 }, { "text": "a variable called lines now suppose I", "start": 1021.5, "duration": 4.319 }, { "text": "want to iterate over all of those lines", "start": 1024.319, "duration": 4.02 }, { "text": "and print out each of those names for", "start": 1025.819, "duration": 4.921 }, { "text": "line in lines this is just a standard", "start": 1028.339, "duration": 6.061 }, { "text": "for Loop in Python lines as a list line", "start": 1030.74, "duration": 4.92 }, { "text": "is the variable that will be", "start": 1034.4, "duration": 3.059 }, { "text": "automatically be set to each of those", "start": 1035.66, "duration": 3.539 }, { "text": "lines let me go ahead and print out", "start": 1037.459, "duration": 3.96 }, { "text": "something like oh hello", "start": 1039.199, "duration": 5.1 }, { "text": "uh comma and then I'll print out the", "start": 1041.419, "duration": 4.201 }, { "text": "line itself", "start": 1044.299, "duration": 3.301 }, { "text": "all right so let me go to my terminal", "start": 1045.62, "duration": 5.64 }, { "text": "window run python of names.pi now I have", "start": 1047.6, "duration": 5.939 }, { "text": "not deleted names.txt so it still", "start": 1051.26, "duration": 3.96 }, { "text": "contains all four of those names and hit", "start": 1053.539, "duration": 5.701 }, { "text": "enter and okay it's not bad but it's a", "start": 1055.22, "duration": 6.0 }, { "text": "little ugly here", "start": 1059.24, "duration": 4.799 }, { "text": "what's going on when I ran names.pi it's", "start": 1061.22, "duration": 4.74 }, { "text": "saying hello to Hermione to Harry to Ron", "start": 1064.039, "duration": 4.02 }, { "text": "to Draco but there's these gaps now", "start": 1065.96, "duration": 4.579 }, { "text": "between the lines", "start": 1068.059, "duration": 5.581 }, { "text": "what's explains that symptom if if", "start": 1070.539, "duration": 5.02 }, { "text": "nothing else it just looks ugly it", "start": 1073.64, "duration": 4.32 }, { "text": "happens because in the text file we have", "start": 1075.559, "duration": 5.641 }, { "text": "new line symbols uh in between those", "start": 1077.96, "duration": 6.3 }, { "text": "names and the print always adds another", "start": 1081.2, "duration": 6.479 }, { "text": "new line at the end so you you use the", "start": 1084.26, "duration": 5.94 }, { "text": "same symbol twice perfect and here's a", "start": 1087.679, "duration": 4.38 }, { "text": "good example of a bug a mistake in a", "start": 1090.2, "duration": 3.18 }, { "text": "program but if you just think about", "start": 1092.059, "duration": 3.961 }, { "text": "those first principles like how do each", "start": 1093.38, "duration": 4.799 }, { "text": "of the lines of code work that I'm using", "start": 1096.02, "duration": 3.72 }, { "text": "you should be able to reason exactly as", "start": 1098.179, "duration": 3.12 }, { "text": "Rafal did there to say that all right", "start": 1099.74, "duration": 2.88 }, { "text": "well one of those new lines is coming", "start": 1101.299, "duration": 3.601 }, { "text": "from the file after each name and then", "start": 1102.62, "duration": 4.02 }, { "text": "of course print all of these Weeks Later", "start": 1104.9, "duration": 3.96 }, { "text": "is still giving us for free that extra", "start": 1106.64, "duration": 4.08 }, { "text": "new line so there's a couple of possible", "start": 1108.86, "duration": 4.08 }, { "text": "solutions I could certainly do this", "start": 1110.72, "duration": 4.079 }, { "text": "which we've done in the past and pass in", "start": 1112.94, "duration": 3.66 }, { "text": "a named argument to print like end", "start": 1114.799, "duration": 4.921 }, { "text": "equals quote unquote and that's fine I", "start": 1116.6, "duration": 4.62 }, { "text": "would argue a little better than that", "start": 1119.72, "duration": 3.42 }, { "text": "might actually be to do this to strip", "start": 1121.22, "duration": 4.86 }, { "text": "off of the end of the line the actual", "start": 1123.14, "duration": 4.919 }, { "text": "new line itself so that print is", "start": 1126.08, "duration": 3.9 }, { "text": "handling the printing of everything the", "start": 1128.059, "duration": 3.601 }, { "text": "person's name game as well as the new", "start": 1129.98, "duration": 4.14 }, { "text": "line but you're just stripping off what", "start": 1131.66, "duration": 4.379 }, { "text": "is really just an implementation detail", "start": 1134.12, "duration": 4.38 }, { "text": "in the file we chose to use new lines in", "start": 1136.039, "duration": 4.741 }, { "text": "my text file to separate one name from", "start": 1138.5, "duration": 4.799 }, { "text": "another so arguably it should be a", "start": 1140.78, "duration": 4.44 }, { "text": "little cleaner in terms of design to", "start": 1143.299, "duration": 4.201 }, { "text": "strip that off and then let print print", "start": 1145.22, "duration": 4.44 }, { "text": "out what is really just now a name but", "start": 1147.5, "duration": 3.66 }, { "text": "that's ultimately a design decision the", "start": 1149.66, "duration": 4.139 }, { "text": "effect is going to be exactly the same", "start": 1151.16, "duration": 6.36 }, { "text": "well if I'm going to open this file and", "start": 1153.799, "duration": 6.061 }, { "text": "read all the lines and then iterate over", "start": 1157.52, "duration": 3.96 }, { "text": "all of those lines and print them each", "start": 1159.86, "duration": 3.48 }, { "text": "out I could actually combine this into", "start": 1161.48, "duration": 3.66 }, { "text": "one thing because right now I'm doing", "start": 1163.34, "duration": 3.6 }, { "text": "twice as much work I'm reading all of", "start": 1165.14, "duration": 4.38 }, { "text": "the lines then I'm iterating over all of", "start": 1166.94, "duration": 4.92 }, { "text": "the lines just to print out each of them", "start": 1169.52, "duration": 4.56 }, { "text": "well in Python with files you can", "start": 1171.86, "duration": 3.78 }, { "text": "actually do this I'm going to erase", "start": 1174.08, "duration": 3.9 }, { "text": "almost all of these lines now keeping", "start": 1175.64, "duration": 4.919 }, { "text": "only the with statement at top and", "start": 1177.98, "duration": 4.559 }, { "text": "inside of this with statement I'm going", "start": 1180.559, "duration": 6.061 }, { "text": "to say this for line in file go ahead", "start": 1182.539, "duration": 6.421 }, { "text": "and print out quote unquote hello comma", "start": 1186.62, "duration": 4.98 }, { "text": "and then line Dot R strip so I'm going", "start": 1188.96, "duration": 3.839 }, { "text": "to take the approach of stripping off", "start": 1191.6, "duration": 3.42 }, { "text": "the end of the line but notice how", "start": 1192.799, "duration": 5.101 }, { "text": "elegant this is so to speak I've opened", "start": 1195.02, "duration": 5.039 }, { "text": "the file in line one and if I want to", "start": 1197.9, "duration": 4.2 }, { "text": "iterate over every line in the file I", "start": 1200.059, "duration": 4.141 }, { "text": "don't have to very explicitly load all", "start": 1202.1, "duration": 4.319 }, { "text": "read all the lines then iterate over all", "start": 1204.2, "duration": 3.719 }, { "text": "of the lines I can combine this into one", "start": 1206.419, "duration": 3.901 }, { "text": "thought it in Python you can simply say", "start": 1207.919, "duration": 4.681 }, { "text": "for line and file and that's going to", "start": 1210.32, "duration": 3.719 }, { "text": "have the effect of giving you a for Loop", "start": 1212.6, "duration": 3.42 }, { "text": "that iterates over every line in the", "start": 1214.039, "duration": 3.901 }, { "text": "file one at a time and on each iteration", "start": 1216.02, "duration": 4.38 }, { "text": "updating the value of this variable line", "start": 1217.94, "duration": 6.359 }, { "text": "to be Hermione then Harry then Ron then", "start": 1220.4, "duration": 6.12 }, { "text": "Draco so this again is one of the", "start": 1224.299, "duration": 4.201 }, { "text": "appealing aspects of python is that it", "start": 1226.52, "duration": 3.779 }, { "text": "reads rather like English for line and", "start": 1228.5, "duration": 4.679 }, { "text": "file print this it's a little more", "start": 1230.299, "duration": 5.581 }, { "text": "compact when written this way well what", "start": 1233.179, "duration": 3.661 }, { "text": "if though", "start": 1235.88, "duration": 2.94 }, { "text": "I don't want quite this Behavior because", "start": 1236.84, "duration": 4.319 }, { "text": "notice now if I run python of names.pi", "start": 1238.82, "duration": 4.739 }, { "text": "it's correct I'm seeing each of the", "start": 1241.159, "duration": 4.26 }, { "text": "names and each of the hellos and there's", "start": 1243.559, "duration": 5.1 }, { "text": "no Extra Spaces in between but just to", "start": 1245.419, "duration": 5.64 }, { "text": "be difficult I'd really like us to be", "start": 1248.659, "duration": 4.681 }, { "text": "sorting these hellos really I'd like to", "start": 1251.059, "duration": 4.98 }, { "text": "see Draco first then Harry then Hermione", "start": 1253.34, "duration": 4.5 }, { "text": "then Ron no matter what order they", "start": 1256.039, "duration": 4.02 }, { "text": "appear in the file so I could go in of", "start": 1257.84, "duration": 3.839 }, { "text": "course to the file and manually change", "start": 1260.059, "duration": 3.12 }, { "text": "the file but if that file is changing", "start": 1261.679, "duration": 3.601 }, { "text": "over time based on who is typing their", "start": 1263.179, "duration": 3.661 }, { "text": "name into the program that's not really", "start": 1265.28, "duration": 3.42 }, { "text": "a good solution in code I should be able", "start": 1266.84, "duration": 3.54 }, { "text": "to load the file no matter what it looks", "start": 1268.7, "duration": 4.8 }, { "text": "like and just sort it all at once now", "start": 1270.38, "duration": 5.7 }, { "text": "here is a reason to not do what I've", "start": 1273.5, "duration": 6.12 }, { "text": "just done I can't iterate over each line", "start": 1276.08, "duration": 6.12 }, { "text": "in the file and print it out but sort", "start": 1279.62, "duration": 4.86 }, { "text": "everything in advance right logically if", "start": 1282.2, "duration": 4.32 }, { "text": "I'm looking at each line one at a time", "start": 1284.48, "duration": 4.5 }, { "text": "and printing it out it's too late to", "start": 1286.52, "duration": 4.44 }, { "text": "sort I really need to read all of the", "start": 1288.98, "duration": 4.559 }, { "text": "lines first without printing them sort", "start": 1290.96, "duration": 4.5 }, { "text": "them then print them so we have to take", "start": 1293.539, "duration": 3.961 }, { "text": "a step back in order to add now now this", "start": 1295.46, "duration": 4.14 }, { "text": "new feature so how can I do this well", "start": 1297.5, "duration": 4.14 }, { "text": "let me combine some ideas from before", "start": 1299.6, "duration": 4.319 }, { "text": "let me go ahead and start fresh with", "start": 1301.64, "duration": 4.26 }, { "text": "this let me give myself a list called", "start": 1303.919, "duration": 4.681 }, { "text": "names and assign it an empty list just", "start": 1305.9, "duration": 4.5 }, { "text": "so I have a variable in which to", "start": 1308.6, "duration": 4.02 }, { "text": "accumulate all of these lines and now", "start": 1310.4, "duration": 4.86 }, { "text": "let me open the file with open quote", "start": 1312.62, "duration": 4.98 }, { "text": "unquote names.txt and it turns out I can", "start": 1315.26, "duration": 4.02 }, { "text": "tighten this up a little bit it turns", "start": 1317.6, "duration": 3.24 }, { "text": "out if you're opening a file to read it", "start": 1319.28, "duration": 3.72 }, { "text": "you don't need to specify quote unquote", "start": 1320.84, "duration": 4.68 }, { "text": "r that is the implicit default so you", "start": 1323.0, "duration": 4.02 }, { "text": "can tighten things up by just saying", "start": 1325.52, "duration": 3.24 }, { "text": "open names.text and you'll be able to", "start": 1327.02, "duration": 4.019 }, { "text": "read the file but not write it I'm going", "start": 1328.76, "duration": 4.2 }, { "text": "to give myself a variable called file as", "start": 1331.039, "duration": 4.321 }, { "text": "before I am going to iterate over the", "start": 1332.96, "duration": 4.68 }, { "text": "file in the same way for line in file", "start": 1335.36, "duration": 5.28 }, { "text": "but instead of printing each line I'm", "start": 1337.64, "duration": 5.22 }, { "text": "going to do this I'm going to take my", "start": 1340.64, "duration": 5.1 }, { "text": "names list and append to it and this is", "start": 1342.86, "duration": 5.52 }, { "text": "appending to a list in memory not", "start": 1345.74, "duration": 5.22 }, { "text": "appending to the file itself I'm going", "start": 1348.38, "duration": 4.08 }, { "text": "to go ahead and append the current line", "start": 1350.96, "duration": 3.9 }, { "text": "but I'm going to strip off the new line", "start": 1352.46, "duration": 4.079 }, { "text": "at the end so that all I'm adding to", "start": 1354.86, "duration": 4.52 }, { "text": "this list is each of the students names", "start": 1356.539, "duration": 5.221 }, { "text": "now I can use that familiar technique", "start": 1359.38, "duration": 5.02 }, { "text": "from before let me go outside of this", "start": 1361.76, "duration": 4.32 }, { "text": "with statement because now I've read the", "start": 1364.4, "duration": 3.48 }, { "text": "entire file presumably so by the time", "start": 1366.08, "duration": 4.56 }, { "text": "I'm done with lines four and five again", "start": 1367.88, "duration": 4.26 }, { "text": "and again and again for each line in the", "start": 1370.64, "duration": 3.539 }, { "text": "file I'm done with the file it can close", "start": 1372.14, "duration": 4.14 }, { "text": "I now have all of the students names in", "start": 1374.179, "duration": 5.101 }, { "text": "this list variable let me do this for", "start": 1376.28, "duration": 7.019 }, { "text": "name in not just names but the sorted", "start": 1379.28, "duration": 6.72 }, { "text": "names using our python function sorted", "start": 1383.299, "duration": 5.281 }, { "text": "which does just that and do print quote", "start": 1386.0, "duration": 5.4 }, { "text": "unquote with an F string hello comma and", "start": 1388.58, "duration": 5.28 }, { "text": "now I'll plug in bracket name", "start": 1391.4, "duration": 5.7 }, { "text": "so now what have I done I'm creating a", "start": 1393.86, "duration": 4.74 }, { "text": "list at the beginning just so I have a", "start": 1397.1, "duration": 3.9 }, { "text": "place to gather my data I then on lines", "start": 1398.6, "duration": 4.26 }, { "text": "three through five iterate over the file", "start": 1401.0, "duration": 4.26 }, { "text": "from top to bottom reading in each line", "start": 1402.86, "duration": 4.08 }, { "text": "one at a time stripping off the new line", "start": 1405.26, "duration": 3.299 }, { "text": "and adding just the student's name to", "start": 1406.94, "duration": 3.599 }, { "text": "this list and the reason I'm doing that", "start": 1408.559, "duration": 4.98 }, { "text": "is so that on line seven I can sort all", "start": 1410.539, "duration": 4.681 }, { "text": "of those names now that they're all in", "start": 1413.539, "duration": 4.561 }, { "text": "memory and print them in order I need to", "start": 1415.22, "duration": 4.86 }, { "text": "load them all into memory before I can", "start": 1418.1, "duration": 3.84 }, { "text": "sort them otherwise I'd be printing them", "start": 1420.08, "duration": 3.719 }, { "text": "out prematurely and Draco would end up", "start": 1421.94, "duration": 4.14 }, { "text": "last instead of first so let me go ahead", "start": 1423.799, "duration": 4.141 }, { "text": "in my terminal window and run python of", "start": 1426.08, "duration": 5.04 }, { "text": "names.pi now and hit enter and there we", "start": 1427.94, "duration": 6.119 }, { "text": "go the same list of four hellos but now", "start": 1431.12, "duration": 4.919 }, { "text": "they're sorted and this is a very common", "start": 1434.059, "duration": 4.081 }, { "text": "technique when dealing with files and", "start": 1436.039, "duration": 3.721 }, { "text": "information more generally if you want", "start": 1438.14, "duration": 4.26 }, { "text": "to change that data in some way like", "start": 1439.76, "duration": 4.799 }, { "text": "sorting it creating some kind of", "start": 1442.4, "duration": 3.779 }, { "text": "variable at the top of your program like", "start": 1444.559, "duration": 3.72 }, { "text": "a list adding or appending information", "start": 1446.179, "duration": 4.261 }, { "text": "to it just to collect it in one place", "start": 1448.279, "duration": 4.441 }, { "text": "and then do something interesting with", "start": 1450.44, "duration": 4.5 }, { "text": "that collection that list is exactly", "start": 1452.72, "duration": 4.38 }, { "text": "what I've done here now I should note", "start": 1454.94, "duration": 4.14 }, { "text": "that if we just want to sort the file we", "start": 1457.1, "duration": 3.84 }, { "text": "can actually do this even more simply in", "start": 1459.08, "duration": 3.959 }, { "text": "Python particularly by not bothering", "start": 1460.94, "duration": 4.68 }, { "text": "with this names list nor the second for", "start": 1463.039, "duration": 4.14 }, { "text": "Loop and let me go ahead and instead", "start": 1465.62, "duration": 3.539 }, { "text": "just do more simply this let me go ahead", "start": 1467.179, "duration": 3.781 }, { "text": "and tell python that we want the file", "start": 1469.159, "duration": 4.02 }, { "text": "itself to be sorted using that same", "start": 1470.96, "duration": 4.199 }, { "text": "sorted function but this time on the", "start": 1473.179, "duration": 4.201 }, { "text": "file itself and then inside of that for", "start": 1475.159, "duration": 3.721 }, { "text": "Loop let's just go ahead and print right", "start": 1477.38, "duration": 4.26 }, { "text": "away our hello comma followed by the", "start": 1478.88, "duration": 4.679 }, { "text": "line itself but still stripping off of", "start": 1481.64, "duration": 4.68 }, { "text": "the end of it any white space therein if", "start": 1483.559, "duration": 4.261 }, { "text": "we go ahead and run this same program", "start": 1486.32, "duration": 4.02 }, { "text": "now with pythonupnames.pi and hit enter", "start": 1487.82, "duration": 4.26 }, { "text": "we get the same result but of course", "start": 1490.34, "duration": 4.14 }, { "text": "it's a lot more compact but for the sake", "start": 1492.08, "duration": 4.68 }, { "text": "of discussion let's assume that we do", "start": 1494.48, "duration": 4.5 }, { "text": "actually want to potentially make some", "start": 1496.76, "duration": 3.96 }, { "text": "changes to the data as we iterate over", "start": 1498.98, "duration": 3.48 }, { "text": "it so let me undo those changes leave", "start": 1500.72, "duration": 3.72 }, { "text": "things as is where by now we'll continue", "start": 1502.46, "duration": 3.719 }, { "text": "to accumulate all of the names first", "start": 1504.44, "duration": 3.719 }, { "text": "into a list maybe do something to them", "start": 1506.179, "duration": 3.421 }, { "text": "maybe forcing them to uppercase or", "start": 1508.159, "duration": 3.541 }, { "text": "lowercase or the like and then sort and", "start": 1509.6, "duration": 3.78 }, { "text": "print out each item", "start": 1511.7, "duration": 3.18 }, { "text": "let me pause and see if there's any", "start": 1513.38, "duration": 3.84 }, { "text": "questions now on file IO reading or", "start": 1514.88, "duration": 6.0 }, { "text": "writing or now accumulating all of these", "start": 1517.22, "duration": 7.079 }, { "text": "values in some list hi is there a way to", "start": 1520.88, "duration": 5.94 }, { "text": "sort the files but instead if you want", "start": 1524.299, "duration": 5.641 }, { "text": "it from alphabetically from A to Z is", "start": 1526.82, "duration": 5.219 }, { "text": "there a way to reverse it from zet to a", "start": 1529.94, "duration": 4.38 }, { "text": "is there a like a little extension that", "start": 1532.039, "duration": 3.661 }, { "text": "you can add to the end to do that or", "start": 1534.32, "duration": 2.88 }, { "text": "would you have to create a new function", "start": 1535.7, "duration": 4.079 }, { "text": "if you wanted to reverse the contents of", "start": 1537.2, "duration": 5.4 }, { "text": "the file yeah so if you instead of", "start": 1539.779, "duration": 4.921 }, { "text": "sorting them from a to z in ascending", "start": 1542.6, "duration": 3.6 }, { "text": "order if you're one of them in", "start": 1544.7, "duration": 2.76 }, { "text": "descending order", "start": 1546.2, "duration": 4.26 }, { "text": "is there an extension for the there is", "start": 1547.46, "duration": 5.219 }, { "text": "indeed and as always the documentation", "start": 1550.46, "duration": 4.079 }, { "text": "is your friend so if the goal is to sort", "start": 1552.679, "duration": 3.48 }, { "text": "them not in alphabetical order which is", "start": 1554.539, "duration": 2.88 }, { "text": "the default but maybe reverse", "start": 1556.159, "duration": 2.941 }, { "text": "alphabetical order you can take a look", "start": 1557.419, "duration": 3.181 }, { "text": "for instance at the formal python", "start": 1559.1, "duration": 3.36 }, { "text": "documentation there and what you'll see", "start": 1560.6, "duration": 3.9 }, { "text": "is this summary you'll see that the", "start": 1562.46, "duration": 3.839 }, { "text": "sorted function takes a first argument", "start": 1564.5, "duration": 4.08 }, { "text": "generally known as an iterable and", "start": 1566.299, "duration": 3.841 }, { "text": "something that's iterable means that you", "start": 1568.58, "duration": 3.479 }, { "text": "can iterate over it that is you can Loop", "start": 1570.14, "duration": 4.139 }, { "text": "over it one thing at a time what the", "start": 1572.059, "duration": 4.141 }, { "text": "rest of this line here means is that you", "start": 1574.279, "duration": 3.9 }, { "text": "can specify a key like how you want to", "start": 1576.2, "duration": 3.959 }, { "text": "sort it but more on that later but this", "start": 1578.179, "duration": 4.321 }, { "text": "last named parameter here is reverse and", "start": 1580.159, "duration": 4.441 }, { "text": "by default per the documentation it's", "start": 1582.5, "duration": 4.559 }, { "text": "false it will not be reversed by default", "start": 1584.6, "duration": 4.439 }, { "text": "but if we change that to true I bet we", "start": 1587.059, "duration": 4.021 }, { "text": "can do that so let me go back to vs code", "start": 1589.039, "duration": 4.14 }, { "text": "here and do just that let me go ahead", "start": 1591.08, "duration": 4.199 }, { "text": "and pass in a second argument to sorted", "start": 1593.179, "duration": 4.74 }, { "text": "in addition to this iterable which is my", "start": 1595.279, "duration": 5.041 }, { "text": "names list iterable again in the sense", "start": 1597.919, "duration": 4.86 }, { "text": "that it can be looped over and let me", "start": 1600.32, "duration": 5.58 }, { "text": "pass in Reverse equals true thereby", "start": 1602.779, "duration": 5.341 }, { "text": "overriding the default of false let me", "start": 1605.9, "duration": 4.74 }, { "text": "now run python of names Dot pie and now", "start": 1608.12, "duration": 5.039 }, { "text": "Ron's at the top and draco's at the", "start": 1610.64, "duration": 4.68 }, { "text": "bottom so there too whenever you have a", "start": 1613.159, "duration": 3.301 }, { "text": "question like that moving forward", "start": 1615.32, "duration": 3.3 }, { "text": "consider what does the documentation say", "start": 1616.46, "duration": 3.9 }, { "text": "and see if there's a germ of an idea", "start": 1618.62, "duration": 3.299 }, { "text": "there because odds are if you have some", "start": 1620.36, "duration": 3.299 }, { "text": "problem odds are some programmer before", "start": 1621.919, "duration": 4.321 }, { "text": "you have had the same question other", "start": 1623.659, "duration": 5.0 }, { "text": "thoughts", "start": 1626.24, "duration": 2.419 }, { "text": "um", "start": 1629.36, "duration": 5.22 }, { "text": "and the second question can we find a", "start": 1630.7, "duration": 6.7 }, { "text": "specific name really good question can", "start": 1634.58, "duration": 4.26 }, { "text": "we limit the number of the names in the", "start": 1637.4, "duration": 3.899 }, { "text": "file and can we find a specific one we", "start": 1638.84, "duration": 4.8 }, { "text": "absolutely could if we were to write", "start": 1641.299, "duration": 4.98 }, { "text": "code we could for instance open the file", "start": 1643.64, "duration": 5.34 }, { "text": "first count how many lines are already", "start": 1646.279, "duration": 4.861 }, { "text": "there and then if there's too many", "start": 1648.98, "duration": 4.799 }, { "text": "already we could just exit with sys.exit", "start": 1651.14, "duration": 4.44 }, { "text": "or some other message to indicate to the", "start": 1653.779, "duration": 4.321 }, { "text": "user that sorry the class is full as for", "start": 1655.58, "duration": 4.74 }, { "text": "finding someone specifically absolutely", "start": 1658.1, "duration": 4.28 }, { "text": "you could imagine opening the file", "start": 1660.32, "duration": 4.44 }, { "text": "iterating over it with a for loop again", "start": 1662.38, "duration": 4.12 }, { "text": "and again and then adding a conditional", "start": 1664.76, "duration": 4.56 }, { "text": "like if the current line equals equals", "start": 1666.5, "duration": 5.34 }, { "text": "Harry then we found the chosen run and", "start": 1669.32, "duration": 4.079 }, { "text": "you can print something like that so you", "start": 1671.84, "duration": 3.18 }, { "text": "can absolutely combine these ideas with", "start": 1673.399, "duration": 3.721 }, { "text": "previous ideas like conditionals to ask", "start": 1675.02, "duration": 4.2 }, { "text": "those same questions how about one other", "start": 1677.12, "duration": 6.48 }, { "text": "question on file IO uh so I just thought", "start": 1679.22, "duration": 5.6 }, { "text": "about", "start": 1683.6, "duration": 5.819 }, { "text": "this function like uh read all lines and", "start": 1684.82, "duration": 9.04 }, { "text": "it looks like it's uh like separate all", "start": 1689.419, "duration": 7.221 }, { "text": "the lines by this special character", "start": 1693.86, "duration": 5.88 }, { "text": "backslash n but it looks like we don't", "start": 1696.64, "duration": 6.399 }, { "text": "need it a character and we we always", "start": 1699.74, "duration": 7.559 }, { "text": "trip it and it looks like some bad", "start": 1703.039, "duration": 7.801 }, { "text": "design of function why why wouldn't we", "start": 1707.299, "duration": 7.201 }, { "text": "just strip it inside this function a", "start": 1710.84, "duration": 6.18 }, { "text": "really good question so we are in my", "start": 1714.5, "duration": 4.86 }, { "text": "examples thus far using our strip to", "start": 1717.02, "duration": 4.86 }, { "text": "reverse uh to strip from the end of the", "start": 1719.36, "duration": 4.5 }, { "text": "line all of this white space you might", "start": 1721.88, "duration": 4.26 }, { "text": "not want to do that in this case I am", "start": 1723.86, "duration": 4.679 }, { "text": "stripping it away because I know that", "start": 1726.14, "duration": 4.32 }, { "text": "each of those lines isn't some generic", "start": 1728.539, "duration": 4.02 }, { "text": "line of text each line really represents", "start": 1730.46, "duration": 5.04 }, { "text": "a name that I have put there myself I'm", "start": 1732.559, "duration": 4.681 }, { "text": "using the new line just to separate one", "start": 1735.5, "duration": 4.08 }, { "text": "value from another in other scenarios", "start": 1737.24, "duration": 4.26 }, { "text": "you might very well want to keep that", "start": 1739.58, "duration": 3.54 }, { "text": "line ending because it's a very long", "start": 1741.5, "duration": 3.72 }, { "text": "series of text or a parallel graph or", "start": 1743.12, "duration": 3.36 }, { "text": "something like that where you want to", "start": 1745.22, "duration": 2.939 }, { "text": "keep it distinct from the others but", "start": 1746.48, "duration": 3.9 }, { "text": "it's just a convention we have to use", "start": 1748.159, "duration": 4.861 }, { "text": "something presumably to separate one", "start": 1750.38, "duration": 4.919 }, { "text": "chunk of text from another there are", "start": 1753.02, "duration": 4.32 }, { "text": "other functions in Python that will in", "start": 1755.299, "duration": 4.021 }, { "text": "fact handle the removal of that white", "start": 1757.34, "duration": 4.439 }, { "text": "space for you read lines though does", "start": 1759.32, "duration": 4.02 }, { "text": "literally that though it reads all of", "start": 1761.779, "duration": 4.561 }, { "text": "the lines as is well allow me to turn", "start": 1763.34, "duration": 5.16 }, { "text": "our attention back to where we left off", "start": 1766.34, "duration": 4.559 }, { "text": "here which is just names to propose that", "start": 1768.5, "duration": 5.159 }, { "text": "with names.text we have an ability it", "start": 1770.899, "duration": 4.38 }, { "text": "seems to store each of these names", "start": 1773.659, "duration": 3.721 }, { "text": "pretty straightforwardly but what if we", "start": 1775.279, "duration": 3.241 }, { "text": "wanted to keep track of other", "start": 1777.38, "duration": 3.299 }, { "text": "information as well suppose that we", "start": 1778.52, "duration": 5.039 }, { "text": "wanted to store information including a", "start": 1780.679, "duration": 6.301 }, { "text": "student's uh name and their house at", "start": 1783.559, "duration": 5.521 }, { "text": "Hogwarts be it Gryffindor or Slytherin", "start": 1786.98, "duration": 4.439 }, { "text": "or something else well where do we go", "start": 1789.08, "duration": 4.26 }, { "text": "about putting that you know Hermione", "start": 1791.419, "duration": 3.36 }, { "text": "lives in Gryffindor so we could do", "start": 1793.34, "duration": 3.0 }, { "text": "something like this in our text file", "start": 1794.779, "duration": 3.9 }, { "text": "Harry lives in Gryffindor so we could do", "start": 1796.34, "duration": 4.559 }, { "text": "that Ron lives in Gryffindor so we could", "start": 1798.679, "duration": 4.441 }, { "text": "do that and Draco lives in Slytherin so", "start": 1800.899, "duration": 5.701 }, { "text": "we could do that but I worry here", "start": 1803.12, "duration": 5.52 }, { "text": "but I worry now that we're mixing apples", "start": 1806.6, "duration": 4.079 }, { "text": "and oranges so to speak like some lines", "start": 1808.64, "duration": 4.32 }, { "text": "or names some lines are houses so this", "start": 1810.679, "duration": 4.201 }, { "text": "probably isn't the best design if only", "start": 1812.96, "duration": 3.78 }, { "text": "because it's confusing or it's ambiguous", "start": 1814.88, "duration": 4.08 }, { "text": "so maybe what we could do is Adopt A", "start": 1816.74, "duration": 3.84 }, { "text": "convention and indeed this is in fact", "start": 1818.96, "duration": 4.079 }, { "text": "what a lot of programmers do they change", "start": 1820.58, "duration": 5.16 }, { "text": "this file not to be names.text but", "start": 1823.039, "duration": 4.64 }, { "text": "instead let me create a new file called", "start": 1825.74, "duration": 5.46 }, { "text": "names.csv CSV stands for comma separated", "start": 1827.679, "duration": 5.38 }, { "text": "values and it's a very common convention", "start": 1831.2, "duration": 4.02 }, { "text": "to store multiple pieces of information", "start": 1833.059, "duration": 5.401 }, { "text": "that are related in the same file and so", "start": 1835.22, "duration": 5.1 }, { "text": "to do this I'm going to separate each of", "start": 1838.46, "duration": 4.02 }, { "text": "these types of data not with another new", "start": 1840.32, "duration": 4.5 }, { "text": "line but simply with a comma I'm going", "start": 1842.48, "duration": 4.199 }, { "text": "to keep each student on their own line", "start": 1844.82, "duration": 3.3 }, { "text": "but I'm going to separate the", "start": 1846.679, "duration": 3.541 }, { "text": "information about each student using a", "start": 1848.12, "duration": 4.679 }, { "text": "comma instead and so now we sort of have", "start": 1850.22, "duration": 4.92 }, { "text": "a two-dimensional file if you will row", "start": 1852.799, "duration": 4.561 }, { "text": "by row we have our students but if you", "start": 1855.14, "duration": 4.44 }, { "text": "think of these commas as representing a", "start": 1857.36, "duration": 3.72 }, { "text": "column even though it's not perfectly", "start": 1859.58, "duration": 2.939 }, { "text": "straight because of the lengths of these", "start": 1861.08, "duration": 4.199 }, { "text": "names it's a little it's a little Jagged", "start": 1862.519, "duration": 4.02 }, { "text": "you can think of these commas as", "start": 1865.279, "duration": 3.601 }, { "text": "representing a column and it turns out", "start": 1866.539, "duration": 4.98 }, { "text": "these CSV files are very commonly used", "start": 1868.88, "duration": 4.44 }, { "text": "when you use something like Microsoft", "start": 1871.519, "duration": 3.54 }, { "text": "Excel Apple numbers or Google", "start": 1873.32, "duration": 3.54 }, { "text": "spreadsheets and you want to export the", "start": 1875.059, "duration": 4.5 }, { "text": "data to share with someone else as a CSV", "start": 1876.86, "duration": 5.699 }, { "text": "file or conversely if you want to import", "start": 1879.559, "duration": 5.401 }, { "text": "a CSV file into your preferred", "start": 1882.559, "duration": 4.441 }, { "text": "spreadsheet software like Excel or", "start": 1884.96, "duration": 3.9 }, { "text": "numbers or Google spreadsheets you can", "start": 1887.0, "duration": 4.2 }, { "text": "do that as well so CSV is a very common", "start": 1888.86, "duration": 4.74 }, { "text": "very simple text format that just", "start": 1891.2, "duration": 5.04 }, { "text": "separates values with commas and", "start": 1893.6, "duration": 4.079 }, { "text": "different types of values ultimately", "start": 1896.24, "duration": 3.72 }, { "text": "with new lines as well let me go ahead", "start": 1897.679, "duration": 5.22 }, { "text": "and run code of students.csv to create a", "start": 1899.96, "duration": 4.559 }, { "text": "brand new file that's initially empty", "start": 1902.899, "duration": 3.841 }, { "text": "and we'll add to it those same names but", "start": 1904.519, "duration": 4.561 }, { "text": "also some other information as well so", "start": 1906.74, "duration": 5.279 }, { "text": "if I now have this new file students.csv", "start": 1909.08, "duration": 5.459 }, { "text": "inside of which is one column of name so", "start": 1912.019, "duration": 4.921 }, { "text": "to speak and one column of houses how do", "start": 1914.539, "duration": 4.5 }, { "text": "I go about changing my code to read not", "start": 1916.94, "duration": 4.02 }, { "text": "just those names but also those names", "start": 1919.039, "duration": 3.661 }, { "text": "and houses so that they're not all on", "start": 1920.96, "duration": 3.9 }, { "text": "one line we somehow have access to both", "start": 1922.7, "duration": 4.74 }, { "text": "type of value separately play well let", "start": 1924.86, "duration": 3.72 }, { "text": "me go ahead and create a new program", "start": 1927.44, "duration": 2.78 }, { "text": "here called", "start": 1928.58, "duration": 4.56 }, { "text": "students.pi and in this program let's go", "start": 1930.22, "duration": 5.199 }, { "text": "about reading not a text file per se but", "start": 1933.14, "duration": 4.74 }, { "text": "a specific type of text file a CSV a", "start": 1935.419, "duration": 4.921 }, { "text": "comma separated values file and to do", "start": 1937.88, "duration": 3.84 }, { "text": "this I'm going to use similar code as", "start": 1940.34, "duration": 4.38 }, { "text": "before I'm going to say with open quote", "start": 1941.72, "duration": 4.04 }, { "text": "unquote", "start": 1944.72, "duration": 3.179 }, { "text": "students.csv I'm not going to bother", "start": 1945.76, "duration": 3.88 }, { "text": "specifying quote unquote R because again", "start": 1947.899, "duration": 3.241 }, { "text": "that's the default but I'm going to give", "start": 1949.64, "duration": 4.44 }, { "text": "myself a variable name of file and then", "start": 1951.14, "duration": 4.44 }, { "text": "in this file I'm going to go ahead and", "start": 1954.08, "duration": 5.339 }, { "text": "do this for line and file as before and", "start": 1955.58, "duration": 5.819 }, { "text": "now I have to be a bit clever here let", "start": 1959.419, "duration": 4.921 }, { "text": "me go back to students.csv looking at", "start": 1961.399, "duration": 5.4 }, { "text": "this file and it seems that on my loop", "start": 1964.34, "duration": 4.199 }, { "text": "on each iteration I'm going to get", "start": 1966.799, "duration": 4.74 }, { "text": "access to the whole line of text I'm not", "start": 1968.539, "duration": 4.62 }, { "text": "going to automatically get access to", "start": 1971.539, "duration": 4.38 }, { "text": "just Hermione or just Gryffindor recall", "start": 1973.159, "duration": 4.441 }, { "text": "that the loop is going to give me each", "start": 1975.919, "duration": 4.681 }, { "text": "full line of text so logically what", "start": 1977.6, "duration": 5.28 }, { "text": "would you propose that we do inside of a", "start": 1980.6, "duration": 4.26 }, { "text": "for Loop that's reading a whole line of", "start": 1982.88, "duration": 3.539 }, { "text": "text at once but we now want to get", "start": 1984.86, "duration": 3.9 }, { "text": "access to the individual values like", "start": 1986.419, "duration": 4.681 }, { "text": "Hermione and Gryffindor Harry and", "start": 1988.76, "duration": 4.799 }, { "text": "Gryffindor how do we go about taking one", "start": 1991.1, "duration": 4.439 }, { "text": "line of text and gaining access to those", "start": 1993.559, "duration": 3.48 }, { "text": "individual values do you think just", "start": 1995.539, "duration": 3.24 }, { "text": "instinctively even if you're not sure", "start": 1997.039, "duration": 3.48 }, { "text": "what the name of the functions would be", "start": 1998.779, "duration": 4.561 }, { "text": "you can access access it as you would", "start": 2000.519, "duration": 4.561 }, { "text": "and if you were using a dictionary like", "start": 2003.34, "duration": 3.3 }, { "text": "using a key and value", "start": 2005.08, "duration": 3.54 }, { "text": "so ideally we would access it using it a", "start": 2006.64, "duration": 3.419 }, { "text": "key in value but at this point in the", "start": 2008.62, "duration": 3.84 }, { "text": "story all we have is this Loop and this", "start": 2010.059, "duration": 4.921 }, { "text": "Loop is giving me one line of text that", "start": 2012.46, "duration": 4.38 }, { "text": "is the time I'm the programmer now I", "start": 2014.98, "duration": 3.059 }, { "text": "have to solve this there is no", "start": 2016.84, "duration": 3.24 }, { "text": "dictionary yet in question about another", "start": 2018.039, "duration": 3.901 }, { "text": "suggestion here", "start": 2020.08, "duration": 4.319 }, { "text": "um so you can somehow split the two", "start": 2021.94, "duration": 5.219 }, { "text": "words based on the comma yeah even if", "start": 2024.399, "duration": 4.561 }, { "text": "you're not quite sure what function is", "start": 2027.159, "duration": 3.541 }, { "text": "going to do this intuitively you want to", "start": 2028.96, "duration": 3.24 }, { "text": "take this whole line of text Hermione", "start": 2030.7, "duration": 4.02 }, { "text": "comma Gryffindor Harry comma Gryffindor", "start": 2032.2, "duration": 5.04 }, { "text": "and so forth and split that line into", "start": 2034.72, "duration": 4.5 }, { "text": "two pieces if you will and it turns out", "start": 2037.24, "duration": 3.419 }, { "text": "wonderfully the function we'll use is", "start": 2039.22, "duration": 3.72 }, { "text": "actually called split that can split on", "start": 2040.659, "duration": 4.38 }, { "text": "any characters but you can tell it what", "start": 2042.94, "duration": 3.9 }, { "text": "character to use so I'm going to go back", "start": 2045.039, "duration": 4.741 }, { "text": "into students.pi and inside of this Loop", "start": 2046.84, "duration": 4.319 }, { "text": "I'm going to go ahead and do this I'm", "start": 2049.78, "duration": 3.359 }, { "text": "going to take the current line I'm going", "start": 2051.159, "duration": 4.2 }, { "text": "to remove the white space at the end as", "start": 2053.139, "duration": 4.5 }, { "text": "always using R strip here and then", "start": 2055.359, "duration": 4.141 }, { "text": "whatever the result of that is I'm going", "start": 2057.639, "duration": 4.861 }, { "text": "to now call split and quote unquote", "start": 2059.5, "duration": 6.24 }, { "text": "comma so the split function or method", "start": 2062.5, "duration": 6.839 }, { "text": "comes with strings stirs in Python any", "start": 2065.74, "duration": 6.659 }, { "text": "stir has this method built in and if you", "start": 2069.339, "duration": 5.461 }, { "text": "pass in an argument like a comma what", "start": 2072.399, "duration": 4.68 }, { "text": "this strip split function will do is", "start": 2074.8, "duration": 4.68 }, { "text": "split that current string into one two", "start": 2077.079, "duration": 5.1 }, { "text": "three maybe more pieces by looking for", "start": 2079.48, "duration": 4.8 }, { "text": "that character again and again", "start": 2082.179, "duration": 5.641 }, { "text": "ultimately strip uh ultimately split is", "start": 2084.28, "duration": 5.639 }, { "text": "going to return to us a list of all of", "start": 2087.82, "duration": 4.079 }, { "text": "the individual parts to the left and to", "start": 2089.919, "duration": 4.321 }, { "text": "the right of those commas so I can give", "start": 2091.899, "duration": 4.381 }, { "text": "myself a variable called row here and", "start": 2094.24, "duration": 3.72 }, { "text": "this is a common Paradigm when you know", "start": 2096.28, "duration": 3.18 }, { "text": "you're iterating over a file", "start": 2097.96, "duration": 4.5 }, { "text": "specifically a CSV it's common to think", "start": 2099.46, "duration": 6.6 }, { "text": "of each line of it as being a row and", "start": 2102.46, "duration": 5.52 }, { "text": "each of the values they're in separated", "start": 2106.06, "duration": 4.74 }, { "text": "by commas as columns so to speak so I'm", "start": 2107.98, "duration": 4.5 }, { "text": "going to deliberately name my variable", "start": 2110.8, "duration": 3.42 }, { "text": "row just to be consistent with that", "start": 2112.48, "duration": 4.2 }, { "text": "convention and now what do I want to", "start": 2114.22, "duration": 4.379 }, { "text": "print well I'm going to go ahead and say", "start": 2116.68, "duration": 5.939 }, { "text": "this print how about the following in F", "start": 2118.599, "duration": 7.081 }, { "text": "string that starts with curly braces", "start": 2122.619, "duration": 6.0 }, { "text": "well how do I get access to the first", "start": 2125.68, "duration": 4.98 }, { "text": "thing in that row well the row is going", "start": 2128.619, "duration": 4.201 }, { "text": "to have how many parts two because if", "start": 2130.66, "duration": 4.02 }, { "text": "I'm splitting on commas and there's one", "start": 2132.82, "duration": 3.96 }, { "text": "comma per line that's going to give me a", "start": 2134.68, "duration": 3.96 }, { "text": "left part and a right part like Hermione", "start": 2136.78, "duration": 4.92 }, { "text": "and Gryffindor Harry and Gryffindor when", "start": 2138.64, "duration": 5.459 }, { "text": "I have a list like row how do I get", "start": 2141.7, "duration": 4.8 }, { "text": "access to individual values well I can", "start": 2144.099, "duration": 6.421 }, { "text": "do this I can say Row Bracket zero and", "start": 2146.5, "duration": 5.64 }, { "text": "that's going to go to the first element", "start": 2150.52, "duration": 3.12 }, { "text": "of the list which should hopefully be", "start": 2152.14, "duration": 3.959 }, { "text": "the student's name then after that I'm", "start": 2153.64, "duration": 4.26 }, { "text": "going to say is in and I'm going to have", "start": 2156.099, "duration": 5.281 }, { "text": "another curly brace here for Row Bracket", "start": 2157.9, "duration": 5.34 }, { "text": "one and then I'm going to close my whole", "start": 2161.38, "duration": 3.84 }, { "text": "quote so it looks a little cryptic at", "start": 2163.24, "duration": 3.54 }, { "text": "first glance but most of this is just F", "start": 2165.22, "duration": 3.899 }, { "text": "string syntax with curly braces to plug", "start": 2166.78, "duration": 4.319 }, { "text": "in values and what values am I plugging", "start": 2169.119, "duration": 4.74 }, { "text": "in well rho again is a list and it has", "start": 2171.099, "duration": 5.581 }, { "text": "two elements presumably Hermione in one", "start": 2173.859, "duration": 4.74 }, { "text": "and Gryffindor and the other and so", "start": 2176.68, "duration": 4.8 }, { "text": "forth so bracket zero is the first", "start": 2178.599, "duration": 4.321 }, { "text": "element because remember we start", "start": 2181.48, "duration": 4.56 }, { "text": "indexing at zero in Python and one is", "start": 2182.92, "duration": 4.98 }, { "text": "going to be the second second element so", "start": 2186.04, "duration": 3.78 }, { "text": "let me go ahead and run this now and see", "start": 2187.9, "duration": 6.02 }, { "text": "what happens python of uh", "start": 2189.82, "duration": 7.92 }, { "text": "students.pi enter and we see Hermione's", "start": 2193.92, "duration": 5.32 }, { "text": "in Gryffindor Harry's and Gryffindor Ron", "start": 2197.74, "duration": 3.48 }, { "text": "is in Gryffindor and Draco is in", "start": 2199.24, "duration": 4.92 }, { "text": "Slytherin so we have now implemented our", "start": 2201.22, "duration": 6.06 }, { "text": "own code from scratch that actually", "start": 2204.16, "duration": 6.36 }, { "text": "parses that is reads and interprets a", "start": 2207.28, "duration": 5.64 }, { "text": "CSV file ultimately here", "start": 2210.52, "duration": 4.2 }, { "text": "now let me pause to see if there's any", "start": 2212.92, "duration": 3.419 }, { "text": "questions but we'll make this even", "start": 2214.72, "duration": 4.2 }, { "text": "easier to read in just a moment", "start": 2216.339, "duration": 4.681 }, { "text": "any questions on what we've just done", "start": 2218.92, "duration": 4.8 }, { "text": "here by splitting by comma so my", "start": 2221.02, "duration": 6.36 }, { "text": "question is uh can we edit any line of", "start": 2223.72, "duration": 6.72 }, { "text": "code anytime we want or uh the only", "start": 2227.38, "duration": 5.82 }, { "text": "option that we have is to append uh the", "start": 2230.44, "duration": 5.82 }, { "text": "lines or let's say if we want to let's", "start": 2233.2, "duration": 6.659 }, { "text": "say change headies uh house to let's say", "start": 2236.26, "duration": 7.2 }, { "text": "Slytherin or some other house yeah a", "start": 2239.859, "duration": 5.22 }, { "text": "really good question what if you want to", "start": 2243.46, "duration": 4.44 }, { "text": "in Python change a line in the file and", "start": 2245.079, "duration": 5.76 }, { "text": "not just a pen to the end you would have", "start": 2247.9, "duration": 4.98 }, { "text": "to implement that logic yourself so for", "start": 2250.839, "duration": 4.561 }, { "text": "instance you could imagine now opening", "start": 2252.88, "duration": 4.68 }, { "text": "the file and reading all of the contents", "start": 2255.4, "duration": 4.679 }, { "text": "in then maybe iterating over each of", "start": 2257.56, "duration": 4.26 }, { "text": "those lines and as soon as you see that", "start": 2260.079, "duration": 4.141 }, { "text": "the current name equals equals Harry you", "start": 2261.82, "duration": 4.44 }, { "text": "could maybe change his house to", "start": 2264.22, "duration": 4.44 }, { "text": "Slytherin and then it would be up to you", "start": 2266.26, "duration": 4.8 }, { "text": "though to write all of those changes", "start": 2268.66, "duration": 4.32 }, { "text": "back to the file so in that case you", "start": 2271.06, "duration": 3.96 }, { "text": "might want to in simplest form read the", "start": 2272.98, "duration": 4.379 }, { "text": "file once and let it close then open it", "start": 2275.02, "duration": 4.5 }, { "text": "again but open for writing and change", "start": 2277.359, "duration": 4.681 }, { "text": "the whole file it's not really possible", "start": 2279.52, "duration": 4.8 }, { "text": "or easy to go in and change just part of", "start": 2282.04, "duration": 4.26 }, { "text": "the file though you can do it it's", "start": 2284.32, "duration": 4.019 }, { "text": "easier to actually read the whole file", "start": 2286.3, "duration": 3.96 }, { "text": "make your changes in memory then write", "start": 2288.339, "duration": 3.961 }, { "text": "the whole file out but for larger files", "start": 2290.26, "duration": 4.02 }, { "text": "where that might be quite slow you can", "start": 2292.3, "duration": 4.62 }, { "text": "be more clever than that well let me", "start": 2294.28, "duration": 4.68 }, { "text": "propose now that we clean this up a", "start": 2296.92, "duration": 3.48 }, { "text": "little bit because I actually think this", "start": 2298.96, "duration": 3.48 }, { "text": "is a little cryptic to read Row Bracket", "start": 2300.4, "duration": 4.199 }, { "text": "zero Row Bracket one it's it's not that", "start": 2302.44, "duration": 4.44 }, { "text": "well written at the moment I would say", "start": 2304.599, "duration": 5.461 }, { "text": "but it turns out that when you have a", "start": 2306.88, "duration": 5.58 }, { "text": "variable that's a list like row you", "start": 2310.06, "duration": 3.72 }, { "text": "don't have to throw all of those", "start": 2312.46, "duration": 3.42 }, { "text": "variables into a list you can actually", "start": 2313.78, "duration": 5.28 }, { "text": "unpack that whole sequence at once that", "start": 2315.88, "duration": 4.739 }, { "text": "is to say if you know that a function", "start": 2319.06, "duration": 4.26 }, { "text": "like split returns a list but you know", "start": 2320.619, "duration": 5.041 }, { "text": "in advance that it's going to return two", "start": 2323.32, "duration": 4.56 }, { "text": "values in a list the first and the", "start": 2325.66, "duration": 4.08 }, { "text": "second you don't have to throw them all", "start": 2327.88, "duration": 3.84 }, { "text": "into a variable that itself is a list", "start": 2329.74, "duration": 3.859 }, { "text": "you can actually unpack them", "start": 2331.72, "duration": 4.26 }, { "text": "simultaneously into two variables doing", "start": 2333.599, "duration": 4.841 }, { "text": "name comma house so this is a nice", "start": 2335.98, "duration": 4.619 }, { "text": "python technique to not only create but", "start": 2338.44, "duration": 3.26 }, { "text": "assign", "start": 2340.599, "duration": 4.441 }, { "text": "automatically in parallel two variables", "start": 2341.7, "duration": 5.8 }, { "text": "at once rather than just one so this", "start": 2345.04, "duration": 4.079 }, { "text": "will have the effect of putting the name", "start": 2347.5, "duration": 3.54 }, { "text": "in the left Hermione and it will have", "start": 2349.119, "duration": 3.48 }, { "text": "the effect of putting Gryffindor the", "start": 2351.04, "duration": 3.66 }, { "text": "house in the right variable and we now", "start": 2352.599, "duration": 4.02 }, { "text": "no longer have a row we can now make our", "start": 2354.7, "duration": 3.36 }, { "text": "code a little more readable by now", "start": 2356.619, "duration": 3.781 }, { "text": "literally just saying name down here and", "start": 2358.06, "duration": 4.5 }, { "text": "for instance house down here so just a", "start": 2360.4, "duration": 3.179 }, { "text": "little more readable even though", "start": 2362.56, "duration": 4.559 }, { "text": "functionally the code now is exactly the", "start": 2363.579, "duration": 4.681 }, { "text": "same", "start": 2367.119, "duration": 3.661 }, { "text": "all right so this now works and I'll", "start": 2368.26, "duration": 4.2 }, { "text": "confirm as much by just running it once", "start": 2370.78, "duration": 4.26 }, { "text": "more python of students.pi enter and we", "start": 2372.46, "duration": 5.28 }, { "text": "see that the text is as intended but", "start": 2375.04, "duration": 4.44 }, { "text": "suppose for the sake of discussion that", "start": 2377.74, "duration": 5.099 }, { "text": "I'd like to sort this list of output I'd", "start": 2379.48, "duration": 5.46 }, { "text": "like to say hello again to Draco first", "start": 2382.839, "duration": 4.381 }, { "text": "then hello to Harry then Hermione then", "start": 2384.94, "duration": 5.04 }, { "text": "Ron how can I go about doing this well", "start": 2387.22, "duration": 4.44 }, { "text": "let's take some inspiration from the", "start": 2389.98, "duration": 3.119 }, { "text": "previous example where we're only", "start": 2391.66, "duration": 4.679 }, { "text": "dealing with names and instead do it", "start": 2393.099, "duration": 5.641 }, { "text": "with these full phrases so and so is", "start": 2396.339, "duration": 4.26 }, { "text": "in-house well let me go ahead and do", "start": 2398.74, "duration": 3.42 }, { "text": "this I'm going to go ahead and start", "start": 2400.599, "duration": 4.02 }, { "text": "scratch and give myself a list called", "start": 2402.16, "duration": 4.56 }, { "text": "students equal to an empty list", "start": 2404.619, "duration": 4.021 }, { "text": "initially and then with open", "start": 2406.72, "duration": 4.379 }, { "text": "students.csv", "start": 2408.64, "duration": 4.979 }, { "text": "as file I'm going to go ahead and say", "start": 2411.099, "duration": 6.181 }, { "text": "this for line in file and then below", "start": 2413.619, "duration": 4.98 }, { "text": "this I'm going to do exactly as before", "start": 2417.28, "duration": 3.66 }, { "text": "name comma house equals the current line", "start": 2418.599, "duration": 4.441 }, { "text": "stripping off the white space at the end", "start": 2420.94, "duration": 4.56 }, { "text": "splitting it on a comma so that's exact", "start": 2423.04, "duration": 5.94 }, { "text": "same as before but this time before I go", "start": 2425.5, "duration": 7.2 }, { "text": "about uh printing the sentence I'm going", "start": 2428.98, "duration": 5.58 }, { "text": "to store it temporarily in a list so", "start": 2432.7, "duration": 3.36 }, { "text": "that I can accumulate all of these", "start": 2434.56, "duration": 3.72 }, { "text": "sentences and then sort them later so", "start": 2436.06, "duration": 4.14 }, { "text": "let me go ahead and do this students", "start": 2438.28, "duration": 5.039 }, { "text": "which is my list dot append let me", "start": 2440.2, "duration": 4.98 }, { "text": "append the actual sentence I want to", "start": 2443.319, "duration": 3.54 }, { "text": "show on the screen so another F string", "start": 2445.18, "duration": 5.52 }, { "text": "so name is in house just as before but", "start": 2446.859, "duration": 5.46 }, { "text": "notice I'm not printing that sentence", "start": 2450.7, "duration": 4.44 }, { "text": "I'm appending it to my list not a file", "start": 2452.319, "duration": 5.881 }, { "text": "but to my list why am I doing this well", "start": 2455.14, "duration": 4.86 }, { "text": "just because as before I want to do this", "start": 2458.2, "duration": 5.82 }, { "text": "for student in the sorted students I", "start": 2460.0, "duration": 6.359 }, { "text": "want to go ahead and print out students", "start": 2464.02, "duration": 4.5 }, { "text": "like this well let me go ahead and run", "start": 2466.359, "duration": 5.581 }, { "text": "python of students.pi and hit enter now", "start": 2468.52, "duration": 5.88 }, { "text": "and I think we'll see indeed Draco is", "start": 2471.94, "duration": 4.02 }, { "text": "now first Harry a second Hermione is", "start": 2474.4, "duration": 4.86 }, { "text": "third and Ron is fourth but this is", "start": 2475.96, "duration": 6.659 }, { "text": "arguably a little sloppy right it seems", "start": 2479.26, "duration": 5.04 }, { "text": "a little hackish that I'm constructing", "start": 2482.619, "duration": 3.661 }, { "text": "these sentences and even though I'm", "start": 2484.3, "duration": 5.16 }, { "text": "technically want to sort by name I'm", "start": 2486.28, "duration": 4.74 }, { "text": "technically sorting by these whole", "start": 2489.46, "duration": 4.2 }, { "text": "English sentences so it's not wrong it's", "start": 2491.02, "duration": 5.04 }, { "text": "achieving the intended result but it's", "start": 2493.66, "duration": 4.14 }, { "text": "not really well designed because I'm", "start": 2496.06, "duration": 3.42 }, { "text": "just kind of getting lucky that English", "start": 2497.8, "duration": 3.059 }, { "text": "is reading from left to right and", "start": 2499.48, "duration": 2.639 }, { "text": "therefore when I print this out it's", "start": 2500.859, "duration": 3.661 }, { "text": "sorting properly it would be better", "start": 2502.119, "duration": 4.141 }, { "text": "really to come up with a technique for", "start": 2504.52, "duration": 4.92 }, { "text": "sorting by the students names not by", "start": 2506.26, "duration": 4.68 }, { "text": "some English sentence that I've", "start": 2509.44, "duration": 3.84 }, { "text": "constructed here on line six", "start": 2510.94, "duration": 4.62 }, { "text": "so to achieve this I'm going to need to", "start": 2513.28, "duration": 4.319 }, { "text": "make my life more complicated for a", "start": 2515.56, "duration": 4.74 }, { "text": "moment and I'm going to need to collect", "start": 2517.599, "duration": 5.76 }, { "text": "information about each student before I", "start": 2520.3, "duration": 4.86 }, { "text": "bother assembling that sentence so let", "start": 2523.359, "duration": 4.021 }, { "text": "me propose that we do this let me go", "start": 2525.16, "duration": 4.199 }, { "text": "ahead and undo these last few lines of", "start": 2527.38, "duration": 4.5 }, { "text": "code so that we currently have two", "start": 2529.359, "duration": 5.101 }, { "text": "variables name and house Each of which", "start": 2531.88, "duration": 3.84 }, { "text": "has name in the student's house", "start": 2534.46, "duration": 2.94 }, { "text": "respectively and we still have our", "start": 2535.72, "duration": 4.26 }, { "text": "Global variable students but let me do", "start": 2537.4, "duration": 4.38 }, { "text": "this recall that python supports", "start": 2539.98, "duration": 3.839 }, { "text": "dictionaries and dictionaries are just", "start": 2541.78, "duration": 4.2 }, { "text": "collections of keys and values so you", "start": 2543.819, "duration": 3.901 }, { "text": "can associate something with something", "start": 2545.98, "duration": 4.68 }, { "text": "else like a name with Hermione like a", "start": 2547.72, "duration": 5.399 }, { "text": "house with Gryffindor that really is a", "start": 2550.66, "duration": 4.38 }, { "text": "dictionary so let me do this let me", "start": 2553.119, "duration": 4.621 }, { "text": "temporarily create a dictionary that", "start": 2555.04, "duration": 5.16 }, { "text": "stores this Association of name with", "start": 2557.74, "duration": 4.8 }, { "text": "house let me go ahead and do this let me", "start": 2560.2, "duration": 4.8 }, { "text": "say that the students here is going to", "start": 2562.54, "duration": 4.02 }, { "text": "be represented initially by an empty", "start": 2565.0, "duration": 2.819 }, { "text": "dictionary and just like you could", "start": 2566.56, "duration": 2.34 }, { "text": "create an empty list with square", "start": 2567.819, "duration": 2.221 }, { "text": "brackets you can create an empty", "start": 2568.9, "duration": 3.719 }, { "text": "dictionary with curly braces so give me", "start": 2570.04, "duration": 4.26 }, { "text": "an empty diction missionary that will", "start": 2572.619, "duration": 4.861 }, { "text": "soon have two keys name and house how do", "start": 2574.3, "duration": 4.799 }, { "text": "I do that well I could do it this way", "start": 2577.48, "duration": 4.8 }, { "text": "student Open Bracket name", "start": 2579.099, "duration": 5.881 }, { "text": "equals the student's name that we got", "start": 2582.28, "duration": 5.24 }, { "text": "from the line student bracket house", "start": 2584.98, "duration": 5.22 }, { "text": "equals the house that we got from the", "start": 2587.52, "duration": 5.92 }, { "text": "line and now I'm going to append to the", "start": 2590.2, "duration": 6.6 }, { "text": "students list plural that particular", "start": 2593.44, "duration": 5.639 }, { "text": "student now why have I done this I've", "start": 2596.8, "duration": 4.08 }, { "text": "admittedly made my code more complicated", "start": 2599.079, "duration": 4.02 }, { "text": "it's more lines of code but I've now", "start": 2600.88, "duration": 4.439 }, { "text": "collected all of the information I have", "start": 2603.099, "duration": 4.801 }, { "text": "about students while still keeping track", "start": 2605.319, "duration": 5.161 }, { "text": "what's a name what's a house the list", "start": 2607.9, "duration": 4.8 }, { "text": "meanwhile has all of the students names", "start": 2610.48, "duration": 4.8 }, { "text": "and houses together now why have I done", "start": 2612.7, "duration": 4.56 }, { "text": "this well let me for the moment just do", "start": 2615.28, "duration": 4.38 }, { "text": "something simple let me do for students", "start": 2617.26, "duration": 4.62 }, { "text": "in students and let me very Simply Now", "start": 2619.66, "duration": 5.76 }, { "text": "say print the following F string the", "start": 2621.88, "duration": 6.38 }, { "text": "current student with this name", "start": 2625.42, "duration": 5.159 }, { "text": "uh is in", "start": 2628.26, "duration": 5.2 }, { "text": "this current student's house", "start": 2630.579, "duration": 5.76 }, { "text": "and now notice one detail inside of this", "start": 2633.46, "duration": 4.859 }, { "text": "F string I'm using my curly braces as", "start": 2636.339, "duration": 2.941 }, { "text": "always", "start": 2638.319, "duration": 3.121 }, { "text": "I'm using inside of those curly braces", "start": 2639.28, "duration": 4.74 }, { "text": "the name of a variable as always but", "start": 2641.44, "duration": 4.8 }, { "text": "then I'm using not bracket zero or one", "start": 2644.02, "duration": 4.14 }, { "text": "because these are dictionaries now not", "start": 2646.24, "duration": 5.579 }, { "text": "list but why am I using single quotes to", "start": 2648.16, "duration": 7.8 }, { "text": "surround house and to surround name", "start": 2651.819, "duration": 7.861 }, { "text": "why single quotes inside of this", "start": 2655.96, "duration": 6.659 }, { "text": "F string", "start": 2659.68, "duration": 7.8 }, { "text": "to access those Keys yes um because you", "start": 2662.619, "duration": 6.301 }, { "text": "have double quotes", "start": 2667.48, "duration": 4.139 }, { "text": "in that in that line 12 and so you have", "start": 2668.92, "duration": 6.24 }, { "text": "to tell python to differentiate exactly", "start": 2671.619, "duration": 4.98 }, { "text": "because I'm already using double quotes", "start": 2675.16, "duration": 4.08 }, { "text": "outside of the F string if I want to put", "start": 2676.599, "duration": 4.321 }, { "text": "quotes around any strings on the inside", "start": 2679.24, "duration": 3.9 }, { "text": "which I do need to do for dictionaries", "start": 2680.92, "duration": 4.32 }, { "text": "because recall when you index into a", "start": 2683.14, "duration": 4.02 }, { "text": "dictionary you don't use numbers like", "start": 2685.24, "duration": 4.68 }, { "text": "lists 0 1 2 onward you instead use", "start": 2687.16, "duration": 4.98 }, { "text": "strings which need to be quoted but if", "start": 2689.92, "duration": 3.899 }, { "text": "you're already using double quotes it's", "start": 2692.14, "duration": 3.479 }, { "text": "easiest to then use single quotes on the", "start": 2693.819, "duration": 3.601 }, { "text": "inside so python doesn't get confused", "start": 2695.619, "duration": 4.561 }, { "text": "about what lines up with what so at the", "start": 2697.42, "duration": 5.1 }, { "text": "moment when I run this program it's", "start": 2700.18, "duration": 4.26 }, { "text": "going to print out those hellos but", "start": 2702.52, "duration": 4.799 }, { "text": "they're not yet sorted in fact what I", "start": 2704.44, "duration": 6.419 }, { "text": "now have is a list of dictionaries and", "start": 2707.319, "duration": 5.52 }, { "text": "nothing is yet sorted but let me tighten", "start": 2710.859, "duration": 3.72 }, { "text": "up the code too to point out that it", "start": 2712.839, "duration": 3.961 }, { "text": "doesn't need to be quite as verbose if", "start": 2714.579, "duration": 4.081 }, { "text": "you're in the habit of creating an empty", "start": 2716.8, "duration": 3.66 }, { "text": "dictionary like this on line six and", "start": 2718.66, "duration": 3.659 }, { "text": "then immediately putting in two keys", "start": 2720.46, "duration": 4.32 }, { "text": "name and house each with two values name", "start": 2722.319, "duration": 4.321 }, { "text": "and house respectively you can actually", "start": 2724.78, "duration": 3.6 }, { "text": "do this all at once so let me show you a", "start": 2726.64, "duration": 3.66 }, { "text": "slightly different different syntax I", "start": 2728.38, "duration": 3.719 }, { "text": "can do this give me a variable called", "start": 2730.3, "duration": 4.5 }, { "text": "student and let me use curly braces on", "start": 2732.099, "duration": 4.141 }, { "text": "the right hand side here but instead of", "start": 2734.8, "duration": 3.24 }, { "text": "leaving them empty let's just Define", "start": 2736.24, "duration": 4.26 }, { "text": "those keys and those values now quote", "start": 2738.04, "duration": 5.1 }, { "text": "unquote name will be name and quote", "start": 2740.5, "duration": 5.46 }, { "text": "unquote house will be house this", "start": 2743.14, "duration": 4.979 }, { "text": "achieves the exact same effect in one", "start": 2745.96, "duration": 5.1 }, { "text": "line instead of three it creates a new", "start": 2748.119, "duration": 5.161 }, { "text": "non-empty dictionary containing a name", "start": 2751.06, "duration": 4.08 }, { "text": "key the value of which is the student's", "start": 2753.28, "duration": 3.96 }, { "text": "name and a house key the value of which", "start": 2755.14, "duration": 4.08 }, { "text": "is the student's house nothing else", "start": 2757.24, "duration": 3.48 }, { "text": "needs to change that will still just", "start": 2759.22, "duration": 4.02 }, { "text": "work so that if I again run python if", "start": 2760.72, "duration": 4.26 }, { "text": "students.pi I'm still seeing those", "start": 2763.24, "duration": 3.78 }, { "text": "greetings but they're still not quite", "start": 2764.98, "duration": 5.16 }, { "text": "actually sorted well what might I go", "start": 2767.02, "duration": 5.7 }, { "text": "about doing here in order to what could", "start": 2770.14, "duration": 5.1 }, { "text": "I do to improve upon this further", "start": 2772.72, "duration": 5.639 }, { "text": "well we need some mechanism now of", "start": 2775.24, "duration": 5.76 }, { "text": "sorting those students but unfortunately", "start": 2778.359, "duration": 6.48 }, { "text": "you can't do this we can't sort all of", "start": 2781.0, "duration": 6.42 }, { "text": "the students now because those students", "start": 2784.839, "duration": 4.621 }, { "text": "are not names like they were before they", "start": 2787.42, "duration": 3.48 }, { "text": "aren't sentences like they were before", "start": 2789.46, "duration": 4.08 }, { "text": "each of the students is a dictionary and", "start": 2790.9, "duration": 4.56 }, { "text": "it's not obvious how you would sort a", "start": 2793.54, "duration": 5.279 }, { "text": "dictionary inside of a list so ideally", "start": 2795.46, "duration": 5.7 }, { "text": "what do we want to do if at the moment", "start": 2798.819, "duration": 5.821 }, { "text": "we hit line 9 we have a list of all of", "start": 2801.16, "duration": 5.459 }, { "text": "these students and inside of that list", "start": 2804.64, "duration": 4.439 }, { "text": "is one dictionary per student and each", "start": 2806.619, "duration": 4.681 }, { "text": "of those dictionaries has two keys name", "start": 2809.079, "duration": 4.201 }, { "text": "and house wouldn't it be nice if there", "start": 2811.3, "duration": 5.1 }, { "text": "were ran code to tell python sort this", "start": 2813.28, "duration": 6.12 }, { "text": "list by looking at this key in each", "start": 2816.4, "duration": 4.56 }, { "text": "dictionary because that would give this", "start": 2819.4, "duration": 4.199 }, { "text": "the ability to sort either by name or", "start": 2820.96, "duration": 4.98 }, { "text": "even by house or even by any other field", "start": 2823.599, "duration": 5.22 }, { "text": "that we add to that file so it turns out", "start": 2825.94, "duration": 5.52 }, { "text": "we can do this we can tell the sorted", "start": 2828.819, "duration": 4.8 }, { "text": "function not just to reverse things or", "start": 2831.46, "duration": 4.34 }, { "text": "not it takes another position National", "start": 2833.619, "duration": 5.341 }, { "text": "it takes another named parameter called", "start": 2835.8, "duration": 5.799 }, { "text": "key where you can specify what key", "start": 2838.96, "duration": 5.34 }, { "text": "should be used in order to sort some", "start": 2841.599, "duration": 4.381 }, { "text": "list of dictionaries and I'm going to", "start": 2844.3, "duration": 3.66 }, { "text": "propose that we do this I'm going to", "start": 2845.98, "duration": 4.139 }, { "text": "first Define a function temporarily for", "start": 2847.96, "duration": 5.099 }, { "text": "now called get name and this functions", "start": 2850.119, "duration": 5.581 }, { "text": "purpose in life given a student is to", "start": 2853.059, "duration": 5.161 }, { "text": "quite simply return the student's name", "start": 2855.7, "duration": 5.1 }, { "text": "from that particular dictionary so if", "start": 2858.22, "duration": 4.56 }, { "text": "student is a dictionary this is going to", "start": 2860.8, "duration": 4.14 }, { "text": "return literally the student's name and", "start": 2862.78, "duration": 4.02 }, { "text": "that's it that's the sole purpose of", "start": 2864.94, "duration": 4.679 }, { "text": "this function in life what do I now want", "start": 2866.8, "duration": 4.68 }, { "text": "to do well now that I have a function", "start": 2869.619, "duration": 4.2 }, { "text": "that given a student will return to me", "start": 2871.48, "duration": 4.98 }, { "text": "the student's name I can do this I can", "start": 2873.819, "duration": 5.821 }, { "text": "change sorted to say use a key that's", "start": 2876.46, "duration": 5.76 }, { "text": "equal to whatever the return value of", "start": 2879.64, "duration": 5.28 }, { "text": "get name is and this now is a feature of", "start": 2882.22, "duration": 5.639 }, { "text": "python python allows you to pass", "start": 2884.92, "duration": 6.54 }, { "text": "functions as arguments in two other", "start": 2887.859, "duration": 6.061 }, { "text": "functions so get name is a function", "start": 2891.46, "duration": 5.94 }, { "text": "sorted is a function and I'm passing in", "start": 2893.92, "duration": 7.5 }, { "text": "get name to sort it as the value of that", "start": 2897.4, "duration": 6.9 }, { "text": "key parameter now why am I doing that", "start": 2901.42, "duration": 4.439 }, { "text": "well if you think of the get name", "start": 2904.3, "duration": 3.96 }, { "text": "function as just a bunch a block of code", "start": 2905.859, "duration": 4.021 }, { "text": "that will get the name of a student", "start": 2908.26, "duration": 3.48 }, { "text": "that's handy because that's the", "start": 2909.88, "duration": 4.199 }, { "text": "capability that sorted needs when given", "start": 2911.74, "duration": 3.9 }, { "text": "a list of students Each of which is a", "start": 2914.079, "duration": 3.961 }, { "text": "dictionary sorted needs to know how do I", "start": 2915.64, "duration": 3.84 }, { "text": "get the name of the student in order to", "start": 2918.04, "duration": 3.12 }, { "text": "do alphabetical sorting for you the", "start": 2919.48, "duration": 3.119 }, { "text": "authors of python didn't know that we", "start": 2921.16, "duration": 2.88 }, { "text": "were going to be creating students here", "start": 2922.599, "duration": 3.0 }, { "text": "in this class so they couldn't have", "start": 2924.04, "duration": 3.84 }, { "text": "anticipated writing code in advance that", "start": 2925.599, "duration": 3.901 }, { "text": "specifically sorts on a field called", "start": 2927.88, "duration": 4.38 }, { "text": "student let alone called name let alone", "start": 2929.5, "duration": 3.9 }, { "text": "house", "start": 2932.26, "duration": 3.96 }, { "text": "so what did they do they instead built", "start": 2933.4, "duration": 5.219 }, { "text": "into the sorted function this named", "start": 2936.22, "duration": 4.74 }, { "text": "parameter key that allows us all these", "start": 2938.619, "duration": 4.321 }, { "text": "years later to tell their function", "start": 2940.96, "duration": 4.139 }, { "text": "sorted how to sort this list of", "start": 2942.94, "duration": 4.679 }, { "text": "dictionaries so now watch what happens", "start": 2945.099, "duration": 5.701 }, { "text": "if I run python of students.pi and hit", "start": 2947.619, "duration": 6.48 }, { "text": "enter I now have a sorted list of output", "start": 2950.8, "duration": 5.64 }, { "text": "why because now that list of", "start": 2954.099, "duration": 5.281 }, { "text": "dictionaries has all been sorted by the", "start": 2956.44, "duration": 4.02 }, { "text": "student's name", "start": 2959.38, "duration": 3.66 }, { "text": "I can further do this if as before we", "start": 2960.46, "duration": 3.899 }, { "text": "want to reverse the whole thing by", "start": 2963.04, "duration": 3.18 }, { "text": "saying reverse equals true we can do", "start": 2964.359, "duration": 3.421 }, { "text": "that too let me rerun python of", "start": 2966.22, "duration": 3.3 }, { "text": "students.pi and hit enter now it's", "start": 2967.78, "duration": 3.96 }, { "text": "reverse now it's Ron then Hermione Harry", "start": 2969.52, "duration": 4.079 }, { "text": "and Draco but we can do something", "start": 2971.74, "duration": 4.56 }, { "text": "different as well what if I want to sort", "start": 2973.599, "duration": 5.941 }, { "text": "for instance by house name reversed I", "start": 2976.3, "duration": 4.74 }, { "text": "could do this I could change this", "start": 2979.54, "duration": 3.96 }, { "text": "function from get name to get house I", "start": 2981.04, "duration": 4.079 }, { "text": "could change the implementation up here", "start": 2983.5, "duration": 4.14 }, { "text": "to be get house and I can return not the", "start": 2985.119, "duration": 4.141 }, { "text": "student's name but the student's house", "start": 2987.64, "duration": 5.66 }, { "text": "and so now notice if I run python of", "start": 2989.26, "duration": 7.44 }, { "text": "students.pi enter notice now it is", "start": 2993.3, "duration": 6.299 }, { "text": "sorted by house in reverse order", "start": 2996.7, "duration": 5.46 }, { "text": "Slytherin is first and then Gryffindor", "start": 2999.599, "duration": 5.321 }, { "text": "if I get rid of the reverse but keep the", "start": 3002.16, "duration": 5.34 }, { "text": "get house and rerun this program now", "start": 3004.92, "duration": 5.639 }, { "text": "it's sorted by house gryffindors first", "start": 3007.5, "duration": 5.52 }, { "text": "and Slytherin is last and the upside now", "start": 3010.559, "duration": 4.441 }, { "text": "of this is because I'm using this list", "start": 3013.02, "duration": 4.5 }, { "text": "of dictionaries and keeping the students", "start": 3015.0, "duration": 4.859 }, { "text": "data together until the last minute when", "start": 3017.52, "duration": 4.38 }, { "text": "I'm finally do doing the printing I now", "start": 3019.859, "duration": 3.72 }, { "text": "have full control over the information", "start": 3021.9, "duration": 4.199 }, { "text": "itself and I can sort by this or that I", "start": 3023.579, "duration": 3.961 }, { "text": "don't have to construct construct those", "start": 3026.099, "duration": 3.301 }, { "text": "sentences in advance like I rather", "start": 3027.54, "duration": 4.38 }, { "text": "hackishly did the first time all right", "start": 3029.4, "duration": 4.5 }, { "text": "that was a lot let me pause here to see", "start": 3031.92, "duration": 4.139 }, { "text": "if there are questions", "start": 3033.9, "duration": 4.74 }, { "text": "so when when we're starting the files", "start": 3036.059, "duration": 5.901 }, { "text": "should we every time should we use the", "start": 3038.64, "duration": 5.459 }, { "text": "loops or", "start": 3041.96, "duration": 5.619 }, { "text": "like uh like a dictionary or or any kind", "start": 3044.099, "duration": 7.681 }, { "text": "of list can be sort by just sorting not", "start": 3047.579, "duration": 6.181 }, { "text": "looping or", "start": 3051.78, "duration": 5.4 }, { "text": "any kind of stuff a good question and", "start": 3053.76, "duration": 5.52 }, { "text": "the short answer with python alone", "start": 3057.18, "duration": 4.32 }, { "text": "you're the programmer you need to do the", "start": 3059.28, "duration": 4.559 }, { "text": "Sorting with libraries and other", "start": 3061.5, "duration": 4.559 }, { "text": "techniques absolutely you can do more of", "start": 3063.839, "duration": 4.201 }, { "text": "this automatically because someone else", "start": 3066.059, "duration": 3.841 }, { "text": "has written that code what we're doing", "start": 3068.04, "duration": 3.42 }, { "text": "at the moment is doing everything from", "start": 3069.9, "duration": 3.419 }, { "text": "scratch ourselves but absolutely with", "start": 3071.46, "duration": 3.3 }, { "text": "other functions or libraries some of", "start": 3073.319, "duration": 4.26 }, { "text": "this could be made uh more uh easily", "start": 3074.76, "duration": 5.339 }, { "text": "done some of this could be made easier", "start": 3077.579, "duration": 4.321 }, { "text": "other questions", "start": 3080.099, "duration": 4.861 }, { "text": "on this technique here it's equal to the", "start": 3081.9, "duration": 7.02 }, { "text": "returned value of the function can it be", "start": 3084.96, "duration": 10.32 }, { "text": "equal to uh just uh a variable or a", "start": 3088.92, "duration": 9.12 }, { "text": "value it well yes it should equal a", "start": 3095.28, "duration": 4.98 }, { "text": "value so I'm speci and I should clarify", "start": 3098.04, "duration": 4.62 }, { "text": "actually since this was not obvious", "start": 3100.26, "duration": 5.16 }, { "text": "so when you pass in a function like get", "start": 3102.66, "duration": 5.52 }, { "text": "name or get house to the sorted function", "start": 3105.42, "duration": 5.58 }, { "text": "as the value of key that function is", "start": 3108.18, "duration": 6.3 }, { "text": "automatically called by the get by the", "start": 3111.0, "duration": 6.24 }, { "text": "sorted function for you on each of the", "start": 3114.48, "duration": 5.579 }, { "text": "dictionaries in the list and it uses the", "start": 3117.24, "duration": 5.22 }, { "text": "return value of get name or get house to", "start": 3120.059, "duration": 5.401 }, { "text": "decide what strings to actually use to", "start": 3122.46, "duration": 5.28 }, { "text": "compare in order to decide which is", "start": 3125.46, "duration": 4.74 }, { "text": "alphabetically correct so this function", "start": 3127.74, "duration": 4.74 }, { "text": "which you pass just by name you do not", "start": 3130.2, "duration": 5.1 }, { "text": "pass in parentheses at the end is called", "start": 3132.48, "duration": 4.98 }, { "text": "by the sorted function in order to", "start": 3135.3, "duration": 5.1 }, { "text": "figure out for you how to compare these", "start": 3137.46, "duration": 6.359 }, { "text": "same values how can we use nested", "start": 3140.4, "duration": 7.5 }, { "text": "dictionaries I have read about the", "start": 3143.819, "duration": 5.821 }, { "text": "nested dictionaries what is the", "start": 3147.9, "duration": 3.6 }, { "text": "difference between nested dictionaries", "start": 3149.64, "duration": 5.28 }, { "text": "and the dictionary inside a list I think", "start": 3151.5, "duration": 5.04 }, { "text": "it is sure", "start": 3154.92, "duration": 3.84 }, { "text": "um uh so we are using a list of", "start": 3156.54, "duration": 4.26 }, { "text": "dictionaries why because each of those", "start": 3158.76, "duration": 3.839 }, { "text": "dictionaries represents a student and a", "start": 3160.8, "duration": 3.72 }, { "text": "student has a name and a house and we", "start": 3162.599, "duration": 3.361 }, { "text": "want to I claim maintain that", "start": 3164.52, "duration": 3.539 }, { "text": "Association and it's a list of students", "start": 3165.96, "duration": 3.72 }, { "text": "because we've got multiple students four", "start": 3168.059, "duration": 4.5 }, { "text": "in this case you could create us a", "start": 3169.68, "duration": 4.379 }, { "text": "structure that is a dictionary of", "start": 3172.559, "duration": 3.121 }, { "text": "dictionaries but I would argue it just", "start": 3174.059, "duration": 3.3 }, { "text": "doesn't solve a problem I don't need a", "start": 3175.68, "duration": 3.179 }, { "text": "dictionary of dictionary I need a list", "start": 3177.359, "duration": 4.561 }, { "text": "of key value pairs right now that's all", "start": 3178.859, "duration": 5.301 }, { "text": "so let me propose if we go back to", "start": 3181.92, "duration": 4.919 }, { "text": "students.pi here and we revert back to", "start": 3184.16, "duration": 5.199 }, { "text": "the approach where we have get name as", "start": 3186.839, "duration": 5.341 }, { "text": "the function both used and defined here", "start": 3189.359, "duration": 4.921 }, { "text": "and that function Returns the student's", "start": 3192.18, "duration": 4.679 }, { "text": "name what happens to be clear is that", "start": 3194.28, "duration": 5.52 }, { "text": "the sorted function will use the value", "start": 3196.859, "duration": 5.941 }, { "text": "of key get name in this case calling", "start": 3199.8, "duration": 5.759 }, { "text": "that function on every dictionary in the", "start": 3202.8, "duration": 5.46 }, { "text": "list that it's supposed to soar and that", "start": 3205.559, "duration": 5.341 }, { "text": "function get name Returns the string", "start": 3208.26, "duration": 4.799 }, { "text": "that sorted will actually use to decide", "start": 3210.9, "duration": 3.719 }, { "text": "whether things go in this order left", "start": 3213.059, "duration": 3.841 }, { "text": "right or in this order right left it", "start": 3214.619, "duration": 4.381 }, { "text": "alphabetizes things based on that return", "start": 3216.9, "duration": 5.04 }, { "text": "value so notice that I'm not calling the", "start": 3219.0, "duration": 4.8 }, { "text": "function get name here with parentheses", "start": 3221.94, "duration": 4.139 }, { "text": "I'm passing it in only by its name so", "start": 3223.8, "duration": 5.1 }, { "text": "that the sorted function can call that", "start": 3226.079, "duration": 5.581 }, { "text": "get name function for me now it turns", "start": 3228.9, "duration": 4.679 }, { "text": "out as always if you're defining", "start": 3231.66, "duration": 3.419 }, { "text": "something be it a variable or in this", "start": 3233.579, "duration": 3.601 }, { "text": "case a function and then immediately", "start": 3235.079, "duration": 5.28 }, { "text": "using it but never once again needing", "start": 3237.18, "duration": 5.22 }, { "text": "the name of that function like get name", "start": 3240.359, "duration": 4.141 }, { "text": "we can actually tighten this code up", "start": 3242.4, "duration": 4.56 }, { "text": "further I can actually do this I can get", "start": 3244.5, "duration": 4.26 }, { "text": "rid of the get name function altogether", "start": 3246.96, "duration": 4.02 }, { "text": "just like I could get rid of a variable", "start": 3248.76, "duration": 4.5 }, { "text": "that isn't strictly necessary and", "start": 3250.98, "duration": 4.74 }, { "text": "instead of passing key the name of a", "start": 3253.26, "duration": 5.28 }, { "text": "function I can actually Pass Key what's", "start": 3255.72, "duration": 5.22 }, { "text": "called an a Lambda function which is an", "start": 3258.54, "duration": 4.2 }, { "text": "anonymous function a function that just", "start": 3260.94, "duration": 3.899 }, { "text": "has no name why because you don't need", "start": 3262.74, "duration": 3.599 }, { "text": "to give it a name if you're only going", "start": 3264.839, "duration": 3.72 }, { "text": "to call it in one place and the syntax", "start": 3266.339, "duration": 4.141 }, { "text": "for this in Python is a little weird but", "start": 3268.559, "duration": 4.56 }, { "text": "if I do key equals literally the word", "start": 3270.48, "duration": 5.639 }, { "text": "Lambda then something like student which", "start": 3273.119, "duration": 4.801 }, { "text": "is the name of the parameter I expect", "start": 3276.119, "duration": 4.081 }, { "text": "this function to take and then I don't", "start": 3277.92, "duration": 4.56 }, { "text": "even type the return key i instead just", "start": 3280.2, "duration": 5.94 }, { "text": "say student bracket name so what am I", "start": 3282.48, "duration": 6.3 }, { "text": "doing here with my code this code here", "start": 3286.14, "duration": 5.219 }, { "text": "that I've highlighted is equivalent to", "start": 3288.78, "duration": 4.799 }, { "text": "the get name function I implemented a", "start": 3291.359, "duration": 4.44 }, { "text": "moment ago the syntax is admittedly a", "start": 3293.579, "duration": 4.081 }, { "text": "little different I don't use def I", "start": 3295.799, "duration": 3.54 }, { "text": "didn't even give it a name like get name", "start": 3297.66, "duration": 3.78 }, { "text": "i instead I'm using this other keyword", "start": 3299.339, "duration": 4.5 }, { "text": "in pi python called Lambda which says", "start": 3301.44, "duration": 4.619 }, { "text": "Hey python here comes a function but it", "start": 3303.839, "duration": 4.74 }, { "text": "has no name it's Anonymous that function", "start": 3306.059, "duration": 4.74 }, { "text": "takes a parameter I could call it", "start": 3308.579, "duration": 3.961 }, { "text": "anything I want I'm calling it student", "start": 3310.799, "duration": 4.741 }, { "text": "why because this function that's passed", "start": 3312.54, "duration": 6.299 }, { "text": "in as key is called on every one of the", "start": 3315.54, "duration": 5.16 }, { "text": "students in that list every one of the", "start": 3318.839, "duration": 4.381 }, { "text": "dictionaries in that list what do I want", "start": 3320.7, "duration": 4.619 }, { "text": "this Anonymous function to return well", "start": 3323.22, "duration": 4.5 }, { "text": "given a student I want to index into", "start": 3325.319, "duration": 4.98 }, { "text": "that dictionary and access their name so", "start": 3327.72, "duration": 4.92 }, { "text": "that the string Hermione and Harry and", "start": 3330.299, "duration": 4.981 }, { "text": "Ron and Draco is ultimately returned and", "start": 3332.64, "duration": 4.62 }, { "text": "that's what the sorted function uses to", "start": 3335.28, "duration": 4.5 }, { "text": "decide how to sort these bigger", "start": 3337.26, "duration": 4.5 }, { "text": "dictionaries that have other Keys like", "start": 3339.78, "duration": 3.72 }, { "text": "house as well", "start": 3341.76, "duration": 3.72 }, { "text": "so if I now go back to my terminal", "start": 3343.5, "duration": 4.5 }, { "text": "window and run python of students.pi it", "start": 3345.48, "duration": 5.22 }, { "text": "still seems to work the same but it's", "start": 3348.0, "duration": 4.38 }, { "text": "arguably a little better design because", "start": 3350.7, "duration": 3.599 }, { "text": "I didn't waste lines of Code by defining", "start": 3352.38, "duration": 3.66 }, { "text": "some other function calling it in one", "start": 3354.299, "duration": 4.32 }, { "text": "and only one place I've done it all sort", "start": 3356.04, "duration": 4.98 }, { "text": "of in one breath if you will", "start": 3358.619, "duration": 3.72 }, { "text": "all right let me pause here to see if", "start": 3361.02, "duration": 3.36 }, { "text": "there's any questions specifically about", "start": 3362.339, "duration": 5.46 }, { "text": "Lambda or Anonymous functions and this", "start": 3364.38, "duration": 5.52 }, { "text": "tightening up of the code", "start": 3367.799, "duration": 4.5 }, { "text": "and I have one question like whether we", "start": 3369.9, "duration": 4.919 }, { "text": "could Define Lambda twice", "start": 3372.299, "duration": 5.221 }, { "text": "can you you can use Lambda twice you can", "start": 3374.819, "duration": 4.5 }, { "text": "create as many Anonymous functions as", "start": 3377.52, "duration": 4.44 }, { "text": "you'd like and you generally use them in", "start": 3379.319, "duration": 4.26 }, { "text": "context like this where you want to pass", "start": 3381.96, "duration": 4.379 }, { "text": "to some other function a function that", "start": 3383.579, "duration": 5.101 }, { "text": "itself does not need a name so you can", "start": 3386.339, "duration": 4.141 }, { "text": "absolutely use it in more than one place", "start": 3388.68, "duration": 4.139 }, { "text": "I just have only one use case for it how", "start": 3390.48, "duration": 4.2 }, { "text": "about one other question on Lambda or", "start": 3392.819, "duration": 3.961 }, { "text": "Anonymous functions specifically what", "start": 3394.68, "duration": 6.24 }, { "text": "what if our Lambda would take more than", "start": 3396.78, "duration": 8.4 }, { "text": "one line for example if sure if your", "start": 3400.92, "duration": 5.58 }, { "text": "Lambda function takes multiple", "start": 3405.18, "duration": 3.54 }, { "text": "parameters that is fine you can simply", "start": 3406.5, "duration": 5.28 }, { "text": "specify commas followed by the names of", "start": 3408.72, "duration": 5.28 }, { "text": "those parameters maybe X and Y or so", "start": 3411.78, "duration": 4.92 }, { "text": "forth after the name student so here too", "start": 3414.0, "duration": 4.38 }, { "text": "Lambda looks a little different from", "start": 3416.7, "duration": 3.96 }, { "text": "Death in that you don't have parentheses", "start": 3418.38, "duration": 3.66 }, { "text": "you don't have the keyword def you don't", "start": 3420.66, "duration": 3.3 }, { "text": "have a function name but ultimately they", "start": 3422.04, "duration": 3.6 }, { "text": "achieve that same effect they create a", "start": 3423.96, "duration": 4.26 }, { "text": "function anonymously and allow you to", "start": 3425.64, "duration": 4.439 }, { "text": "pass it in for instance as some value", "start": 3428.22, "duration": 5.52 }, { "text": "here so let's now change students.csv to", "start": 3430.079, "duration": 5.941 }, { "text": "contain not students houses at Hogwarts", "start": 3433.74, "duration": 4.26 }, { "text": "but their homes where they grew up so", "start": 3436.02, "duration": 4.2 }, { "text": "Draco for instance grew up in Malfoy", "start": 3438.0, "duration": 6.54 }, { "text": "Manor Ron grew up in the borough Harry", "start": 3440.22, "duration": 7.5 }, { "text": "grew up in uh number four", "start": 3444.54, "duration": 6.299 }, { "text": "privet drive and according to the", "start": 3447.72, "duration": 4.98 }, { "text": "internet no one knows where Hermione", "start": 3450.839, "duration": 3.601 }, { "text": "grew up the movies apparently took", "start": 3452.7, "duration": 3.24 }, { "text": "certain liberties with where she grew up", "start": 3454.44, "duration": 2.94 }, { "text": "so for this purpose we're actually going", "start": 3455.94, "duration": 3.359 }, { "text": "to remove Hermione because it is unknown", "start": 3457.38, "duration": 4.08 }, { "text": "exactly where she was born so we still", "start": 3459.299, "duration": 4.681 }, { "text": "have some three students but if anyone", "start": 3461.46, "duration": 6.18 }, { "text": "can spot the potential problem now", "start": 3463.98, "duration": 6.24 }, { "text": "how might this be a bad thing well let's", "start": 3467.64, "duration": 4.32 }, { "text": "go and try and run our own code here let", "start": 3470.22, "duration": 4.2 }, { "text": "me go back to students.pi here and let", "start": 3471.96, "duration": 3.839 }, { "text": "me propose that I just changed my", "start": 3474.42, "duration": 3.12 }, { "text": "semantics because I'm now not thinking", "start": 3475.799, "duration": 3.901 }, { "text": "about Hogwarts houses but the students", "start": 3477.54, "duration": 3.42 }, { "text": "own home so I'm just going to change", "start": 3479.7, "duration": 3.48 }, { "text": "some variables I'm going to change this", "start": 3480.96, "duration": 5.28 }, { "text": "house to a home this house to a home as", "start": 3483.18, "duration": 5.159 }, { "text": "well as this one here I'm still going to", "start": 3486.24, "duration": 3.96 }, { "text": "sort the students by name but I'm going", "start": 3488.339, "duration": 4.26 }, { "text": "to say that they're not in a house but", "start": 3490.2, "duration": 4.98 }, { "text": "rather from a home so I've just changed", "start": 3492.599, "duration": 4.441 }, { "text": "the names of my variables in my grammar", "start": 3495.18, "duration": 4.02 }, { "text": "in English here ultimately to print out", "start": 3497.04, "duration": 4.44 }, { "text": "that for instance Harry is from number", "start": 3499.2, "duration": 5.099 }, { "text": "four privet drive and so forth but let's", "start": 3501.48, "duration": 4.92 }, { "text": "see what happens here when I run python", "start": 3504.299, "duration": 4.141 }, { "text": "of this version of students.pi having", "start": 3506.4, "duration": 5.459 }, { "text": "changed students.csv to contain those", "start": 3508.44, "duration": 6.3 }, { "text": "homes and not houses enter", "start": 3511.859, "duration": 6.421 }, { "text": "huh our first value error like the", "start": 3514.74, "duration": 6.9 }, { "text": "program just doesn't work What might", "start": 3518.28, "duration": 5.76 }, { "text": "explain this value error the explanation", "start": 3521.64, "duration": 5.34 }, { "text": "of which rather cryptically is too many", "start": 3524.04, "duration": 5.16 }, { "text": "values to unpack and the line in", "start": 3526.98, "duration": 6.18 }, { "text": "question is this one involving split how", "start": 3529.2, "duration": 6.3 }, { "text": "did all of a sudden after all of these", "start": 3533.16, "duration": 4.74 }, { "text": "successful runs of this program did line", "start": 3535.5, "duration": 6.079 }, { "text": "five suddenly now break in the line", "start": 3537.9, "duration": 6.3 }, { "text": "instruments.csv you have three values", "start": 3541.579, "duration": 3.941 }, { "text": "there's a line that you have three", "start": 3544.2, "duration": 5.099 }, { "text": "values and incident yeah I spent a lot", "start": 3545.52, "duration": 5.819 }, { "text": "of time trying to figure out where every", "start": 3549.299, "duration": 3.78 }, { "text": "student should be from so that we could", "start": 3551.339, "duration": 3.48 }, { "text": "create this problem for us and", "start": 3553.079, "duration": 3.421 }, { "text": "wonderfully like the first sentence of", "start": 3554.819, "duration": 4.74 }, { "text": "the book is number four privet drive and", "start": 3556.5, "duration": 4.859 }, { "text": "so the fact that that address has a", "start": 3559.559, "duration": 4.321 }, { "text": "comma in it is problematic why because", "start": 3561.359, "duration": 4.681 }, { "text": "you and I decided some time ago to just", "start": 3563.88, "duration": 4.439 }, { "text": "standardize on commas CSV comma", "start": 3566.04, "duration": 7.44 }, { "text": "separated values to denote the uh", "start": 3568.319, "duration": 7.141 }, { "text": "we standardized on commas in order to", "start": 3573.48, "duration": 4.74 }, { "text": "delineate one value from another and if", "start": 3575.46, "duration": 5.52 }, { "text": "we have commas grammatically in the", "start": 3578.22, "duration": 5.04 }, { "text": "student's home we're clearly confusing", "start": 3580.98, "duration": 4.5 }, { "text": "it as this special symbol and the split", "start": 3583.26, "duration": 4.92 }, { "text": "function is now for just Harry trying to", "start": 3585.48, "duration": 5.28 }, { "text": "split it into three values not just two", "start": 3588.18, "duration": 4.56 }, { "text": "and that's why there's too many values", "start": 3590.76, "duration": 4.38 }, { "text": "to unpack because we're only trying to", "start": 3592.74, "duration": 5.64 }, { "text": "assign two variables name and house now", "start": 3595.14, "duration": 5.1 }, { "text": "what could we do here well we could just", "start": 3598.38, "duration": 3.78 }, { "text": "change our approach for instance like", "start": 3600.24, "duration": 4.26 }, { "text": "one Paradigm that is not uncommon is to", "start": 3602.16, "duration": 5.28 }, { "text": "use something a little more", "start": 3604.5, "duration": 5.52 }, { "text": "a little less common like a vertical bar", "start": 3607.44, "duration": 4.679 }, { "text": "so I could go in and change all of my", "start": 3610.02, "duration": 4.44 }, { "text": "commas to Vertical bars that too could", "start": 3612.119, "duration": 4.021 }, { "text": "eventually come back to bite Us in that", "start": 3614.46, "duration": 3.599 }, { "text": "if my file eventually has vertical bar", "start": 3616.14, "duration": 3.9 }, { "text": "somewhere it might still break so maybe", "start": 3618.059, "duration": 3.901 }, { "text": "that's not the best approach I could", "start": 3620.04, "duration": 3.6 }, { "text": "maybe do something like this I could", "start": 3621.96, "duration": 3.78 }, { "text": "escape the data as I've done in the past", "start": 3623.64, "duration": 5.28 }, { "text": "and maybe I could put quotes around any", "start": 3625.74, "duration": 6.18 }, { "text": "English string that itself contains the", "start": 3628.92, "duration": 5.1 }, { "text": "comma and that's fine I could do that", "start": 3631.92, "duration": 5.22 }, { "text": "but then my code students.pi is going to", "start": 3634.02, "duration": 5.039 }, { "text": "have to change too because I can't just", "start": 3637.14, "duration": 4.74 }, { "text": "naively split on a comma Now I'm going", "start": 3639.059, "duration": 4.981 }, { "text": "to have to be smarter about it I'm going", "start": 3641.88, "duration": 4.14 }, { "text": "to have to take into account split only", "start": 3644.04, "duration": 4.38 }, { "text": "on the commas that are not inside of", "start": 3646.02, "duration": 4.559 }, { "text": "quotes and oh it's getting complicated", "start": 3648.42, "duration": 4.32 }, { "text": "fast and at this point you need to take", "start": 3650.579, "duration": 3.661 }, { "text": "a step back and consider you know what", "start": 3652.74, "duration": 3.66 }, { "text": "if we're having this problem odds are", "start": 3654.24, "duration": 4.5 }, { "text": "many other people before us have had the", "start": 3656.4, "duration": 5.04 }, { "text": "same problem it is incredibly common to", "start": 3658.74, "duration": 4.74 }, { "text": "store data in files it is incredibly", "start": 3661.44, "duration": 5.28 }, { "text": "common to use CSV files specifically and", "start": 3663.48, "duration": 5.579 }, { "text": "so you know what why don't we see if", "start": 3666.72, "duration": 4.74 }, { "text": "there's a library in Python that exists", "start": 3669.059, "duration": 6.121 }, { "text": "to read and or write CSV files rather", "start": 3671.46, "duration": 5.82 }, { "text": "than reinvent a wheel so to speak let's", "start": 3675.18, "duration": 3.78 }, { "text": "see if we can write better code by", "start": 3677.28, "duration": 3.36 }, { "text": "standing on the shoulders of others who", "start": 3678.96, "duration": 3.599 }, { "text": "have come before us programmers passed", "start": 3680.64, "duration": 4.08 }, { "text": "and actually use their code to do the", "start": 3682.559, "duration": 4.26 }, { "text": "reading and writing of csvs so we can", "start": 3684.72, "duration": 4.32 }, { "text": "focus on the part of our problem that", "start": 3686.819, "duration": 4.381 }, { "text": "you and I care about so let's propose", "start": 3689.04, "duration": 4.74 }, { "text": "that we go back to our code here and see", "start": 3691.2, "duration": 5.159 }, { "text": "how we might use the CSV Library indeed", "start": 3693.78, "duration": 5.519 }, { "text": "within python there is a module called", "start": 3696.359, "duration": 6.0 }, { "text": "CSV the documentation for it is at this", "start": 3699.299, "duration": 4.681 }, { "text": "URL here in Python's official", "start": 3702.359, "duration": 3.181 }, { "text": "documentation but there's a few", "start": 3703.98, "duration": 3.66 }, { "text": "functions that are pretty readily", "start": 3705.54, "duration": 4.799 }, { "text": "accessible if we just Dive Right In and", "start": 3707.64, "duration": 4.86 }, { "text": "let me propose that we do this let me go", "start": 3710.339, "duration": 4.681 }, { "text": "back to my code here and instead of", "start": 3712.5, "duration": 4.859 }, { "text": "Reinventing this wheel and reading the", "start": 3715.02, "duration": 4.319 }, { "text": "file line by line and splitting on", "start": 3717.359, "duration": 4.2 }, { "text": "commas and dealing now with quotes and", "start": 3719.339, "duration": 4.681 }, { "text": "privet drives and so forth let's do this", "start": 3721.559, "duration": 5.461 }, { "text": "instead at the start of my program let", "start": 3724.02, "duration": 6.48 }, { "text": "me go up and import the CSV module let's", "start": 3727.02, "duration": 5.64 }, { "text": "use this library that someone else has", "start": 3730.5, "duration": 4.079 }, { "text": "written that's dealing with all of these", "start": 3732.66, "duration": 4.139 }, { "text": "Corner cases if you will I'm still going", "start": 3734.579, "duration": 4.621 }, { "text": "to give myself a list initially empty in", "start": 3736.799, "duration": 4.201 }, { "text": "which to store all these students but", "start": 3739.2, "duration": 3.599 }, { "text": "I'm going to change my Approach here now", "start": 3741.0, "duration": 4.74 }, { "text": "just a little bit when I open this file", "start": 3742.799, "duration": 6.121 }, { "text": "with with let me go in here and change", "start": 3745.74, "duration": 5.28 }, { "text": "this a little bit I'm going to go in", "start": 3748.92, "duration": 4.52 }, { "text": "here now and say this", "start": 3751.02, "duration": 6.539 }, { "text": "reader equals CSV dot reader passing in", "start": 3753.44, "duration": 6.46 }, { "text": "file as input so it turns out if you", "start": 3757.559, "duration": 4.081 }, { "text": "read the documentation for the CSV", "start": 3759.9, "duration": 4.02 }, { "text": "module it comes with a function called", "start": 3761.64, "duration": 4.679 }, { "text": "reader whose purpose in life is to read", "start": 3763.92, "duration": 5.52 }, { "text": "a CSV file for you and figure out where", "start": 3766.319, "duration": 4.681 }, { "text": "are the commas where are the quotes", "start": 3769.44, "duration": 3.78 }, { "text": "where are all the the potential Corner", "start": 3771.0, "duration": 4.14 }, { "text": "cases and just deal with them for you", "start": 3773.22, "duration": 3.899 }, { "text": "you can override certain defaults or", "start": 3775.14, "duration": 3.54 }, { "text": "assumptions in case you're using not a", "start": 3777.119, "duration": 3.48 }, { "text": "comma but a pipe or something else but", "start": 3778.68, "duration": 3.659 }, { "text": "by default I think it's just going to", "start": 3780.599, "duration": 4.74 }, { "text": "work now how do I iterate over a reader", "start": 3782.339, "duration": 5.161 }, { "text": "and not the raw file itself it's almost", "start": 3785.339, "duration": 4.26 }, { "text": "the same the library allows you still to", "start": 3787.5, "duration": 6.059 }, { "text": "do this for each row in the reader so", "start": 3789.599, "duration": 5.401 }, { "text": "you're not iterating over the file", "start": 3793.559, "duration": 3.54 }, { "text": "directly now you're iterating over the", "start": 3795.0, "duration": 3.72 }, { "text": "reader which is again going to handle", "start": 3797.099, "duration": 4.02 }, { "text": "all of the parsing of commas and new", "start": 3798.72, "duration": 4.619 }, { "text": "lines and more for each row in the", "start": 3801.119, "duration": 4.801 }, { "text": "reader what am I going to do well at the", "start": 3803.339, "duration": 4.381 }, { "text": "moment I'm going to do this I'm going to", "start": 3805.92, "duration": 4.679 }, { "text": "append to my students list the following", "start": 3807.72, "duration": 5.399 }, { "text": "dictionary a dictionary that has a name", "start": 3810.599, "duration": 5.281 }, { "text": "whose value is the current Row's First", "start": 3813.119, "duration": 5.641 }, { "text": "Column and whose house or rather home", "start": 3815.88, "duration": 6.479 }, { "text": "now is the Rose second column now it's", "start": 3818.76, "duration": 6.299 }, { "text": "worth noting that the reader for each", "start": 3822.359, "duration": 4.861 }, { "text": "line in the file indeed returns to me a", "start": 3825.059, "duration": 4.381 }, { "text": "row but it returns to me a row that's a", "start": 3827.22, "duration": 4.079 }, { "text": "list which is to say that the first", "start": 3829.44, "duration": 3.599 }, { "text": "element of that list is going to be the", "start": 3831.299, "duration": 3.841 }, { "text": "student's name as before the second", "start": 3833.039, "duration": 3.841 }, { "text": "element of that list is going to be the", "start": 3835.14, "duration": 5.76 }, { "text": "student's home as now before but if I", "start": 3836.88, "duration": 5.4 }, { "text": "want to access each of those elements", "start": 3840.9, "duration": 3.54 }, { "text": "remember that lists are zero indexed we", "start": 3842.28, "duration": 3.72 }, { "text": "start counting at zero and then one", "start": 3844.44, "duration": 3.54 }, { "text": "rather than one and then two so if I", "start": 3846.0, "duration": 3.359 }, { "text": "want to get at the student's name I use", "start": 3847.98, "duration": 3.24 }, { "text": "Row Bracket zero and if I want to get at", "start": 3849.359, "duration": 3.541 }, { "text": "the student's home I use Row Bracket one", "start": 3851.22, "duration": 4.44 }, { "text": "but in my for Loop we can do that same", "start": 3852.9, "duration": 5.52 }, { "text": "unpacking as before if I know this CSV", "start": 3855.66, "duration": 5.58 }, { "text": "is only going to have two columns I", "start": 3858.42, "duration": 6.119 }, { "text": "could even do this for name home in", "start": 3861.24, "duration": 5.94 }, { "text": "reader and now I don't need to use list", "start": 3864.539, "duration": 4.8 }, { "text": "notation I can unpack things all at once", "start": 3867.18, "duration": 5.82 }, { "text": "and say name here and home here the rest", "start": 3869.339, "duration": 5.52 }, { "text": "of my code can stay exactly the same", "start": 3873.0, "duration": 3.72 }, { "text": "because what am I doing now on line a", "start": 3874.859, "duration": 3.72 }, { "text": "I'm still constructing the same", "start": 3876.72, "duration": 3.96 }, { "text": "dictionary as before albeit for homes", "start": 3878.579, "duration": 4.561 }, { "text": "instead of houses and I'm grabbing those", "start": 3880.68, "duration": 4.679 }, { "text": "values now not from the file itself and", "start": 3883.14, "duration": 4.38 }, { "text": "my use of split but the reader and again", "start": 3885.359, "duration": 3.841 }, { "text": "what the reader is going to do is figure", "start": 3887.52, "duration": 3.539 }, { "text": "out where are those commas where are the", "start": 3889.2, "duration": 4.02 }, { "text": "quotes and just solve that problem for", "start": 3891.059, "duration": 4.26 }, { "text": "you so let me go now down to my terminal", "start": 3893.22, "duration": 4.5 }, { "text": "window and run python of students.pi and", "start": 3895.319, "duration": 5.121 }, { "text": "hit enter and now we see successfully", "start": 3897.72, "duration": 5.339 }, { "text": "sorted no less that Draco is from", "start": 3900.44, "duration": 5.08 }, { "text": "malform Manor Harry is from number four", "start": 3903.059, "duration": 5.881 }, { "text": "comma privet drive and Ron is from the", "start": 3905.52, "duration": 6.72 }, { "text": "borough questions now on this technique", "start": 3908.94, "duration": 7.74 }, { "text": "of using CSV reader from that CSV module", "start": 3912.24, "duration": 6.72 }, { "text": "which again is just getting us out of", "start": 3916.68, "duration": 3.78 }, { "text": "the business of reading each line", "start": 3918.96, "duration": 3.659 }, { "text": "ourself and reading each of those commas", "start": 3920.46, "duration": 4.74 }, { "text": "and splitting so my questions related to", "start": 3922.619, "duration": 4.621 }, { "text": "Something in the past", "start": 3925.2, "duration": 4.8 }, { "text": "um I recognize that you are reading a", "start": 3927.24, "duration": 6.24 }, { "text": "file every time you well you we're", "start": 3930.0, "duration": 6.24 }, { "text": "assuming that we have the CSV file to", "start": 3933.48, "duration": 5.52 }, { "text": "hand already in this case", "start": 3936.24, "duration": 6.26 }, { "text": "um is it possible to make a file", "start": 3939.0, "duration": 7.74 }, { "text": "readable and writable so in in in case", "start": 3942.5, "duration": 7.0 }, { "text": "if you want you could you could write", "start": 3946.74, "duration": 5.879 }, { "text": "some stuff to the file but then at the", "start": 3949.5, "duration": 4.26 }, { "text": "same time you could have another", "start": 3952.619, "duration": 3.48 }, { "text": "function that reads through the phone", "start": 3953.76, "duration": 5.039 }, { "text": "that's changes to it as you go along a", "start": 3956.099, "duration": 3.96 }, { "text": "really good question and the short", "start": 3958.799, "duration": 3.841 }, { "text": "answer is yes however historically the", "start": 3960.059, "duration": 4.381 }, { "text": "mental model for a file is that of a", "start": 3962.64, "duration": 3.719 }, { "text": "cassette tape years ago not really in", "start": 3964.44, "duration": 4.26 }, { "text": "use anymore but cassette tapes are", "start": 3966.359, "duration": 4.021 }, { "text": "sequential whereby they start at the", "start": 3968.7, "duration": 2.879 }, { "text": "beginning and if you want to get to the", "start": 3970.38, "duration": 3.419 }, { "text": "end you kind of have to unwind the tape", "start": 3971.579, "duration": 4.081 }, { "text": "to get to that point the closest analog", "start": 3973.799, "duration": 3.421 }, { "text": "nowadays would be something like Netflix", "start": 3975.66, "duration": 3.6 }, { "text": "or any streaming service where there's a", "start": 3977.22, "duration": 3.72 }, { "text": "scrubber that you have to go left to", "start": 3979.26, "duration": 3.42 }, { "text": "right you can't just jump there or jump", "start": 3980.94, "duration": 3.899 }, { "text": "there you don't have Random Access so", "start": 3982.68, "duration": 3.659 }, { "text": "the problem with files if you want to", "start": 3984.839, "duration": 3.72 }, { "text": "read and write them you or some Library", "start": 3986.339, "duration": 4.321 }, { "text": "needs to keep track of where you are in", "start": 3988.559, "duration": 3.54 }, { "text": "the file so that if you're reading from", "start": 3990.66, "duration": 3.54 }, { "text": "the top and then you write at the bottom", "start": 3992.099, "duration": 3.601 }, { "text": "and you want to start reading again you", "start": 3994.2, "duration": 3.54 }, { "text": "seek back to the beginning so it's not", "start": 3995.7, "duration": 3.419 }, { "text": "something we'll do here in class it's", "start": 3997.74, "duration": 3.359 }, { "text": "more involved but it's absolutely doable", "start": 3999.119, "duration": 4.081 }, { "text": "for our purposes we'll generally", "start": 4001.099, "duration": 4.02 }, { "text": "recommend read the file and then if you", "start": 4003.2, "duration": 3.3 }, { "text": "want to change it write it back out", "start": 4005.119, "duration": 2.7 }, { "text": "rather than trying to make more", "start": 4006.5, "duration": 3.78 }, { "text": "piecemeal changes which is good if", "start": 4007.819, "duration": 4.441 }, { "text": "though the file is massive and it would", "start": 4010.28, "duration": 4.14 }, { "text": "just be very expensive time wise to", "start": 4012.26, "duration": 4.02 }, { "text": "change the whole thing other questions", "start": 4014.42, "duration": 5.1 }, { "text": "on this CSV reader", "start": 4016.28, "duration": 8.22 }, { "text": "is possible to write a paragraph in that", "start": 4019.52, "duration": 5.819 }, { "text": "file", "start": 4024.5, "duration": 3.119 }, { "text": "absolutely right now I'm writing very", "start": 4025.339, "duration": 4.621 }, { "text": "small strings just names or houses as I", "start": 4027.619, "duration": 4.021 }, { "text": "did before but you can absolutely write", "start": 4029.96, "duration": 4.139 }, { "text": "as much text as you want", "start": 4031.64, "duration": 3.959 }, { "text": "indeed", "start": 4034.099, "duration": 5.541 }, { "text": "other questions on CSV reader", "start": 4035.599, "duration": 4.041 }, { "text": "IP like input key will be your name or", "start": 4041.74, "duration": 7.78 }, { "text": "home so short answer yes we could", "start": 4046.16, "duration": 5.1 }, { "text": "absolutely write a program that prompts", "start": 4049.52, "duration": 4.38 }, { "text": "the user for a name and a home a name", "start": 4051.26, "duration": 4.14 }, { "text": "and a home and we could write out those", "start": 4053.9, "duration": 3.12 }, { "text": "values and in a moment we'll see how you", "start": 4055.4, "duration": 4.8 }, { "text": "can write to a CSV file for now I'm", "start": 4057.02, "duration": 5.96 }, { "text": "assuming as the programmer who created", "start": 4060.2, "duration": 5.04 }, { "text": "students.csv that I know what the", "start": 4062.98, "duration": 3.76 }, { "text": "columns are going to be and therefore", "start": 4065.24, "duration": 3.299 }, { "text": "I'm naming my variables accordingly", "start": 4066.74, "duration": 4.319 }, { "text": "however this is a good segue to one", "start": 4068.539, "duration": 5.101 }, { "text": "final feature of reading csvs which is", "start": 4071.059, "duration": 4.56 }, { "text": "that you don't have to rely on either", "start": 4073.64, "duration": 4.439 }, { "text": "getting a row as a list and using", "start": 4075.619, "duration": 4.68 }, { "text": "bracket zero or bracket one and you", "start": 4078.079, "duration": 4.02 }, { "text": "don't have to unpack things manually in", "start": 4080.299, "duration": 3.901 }, { "text": "this way we could actually be smarter", "start": 4082.099, "duration": 4.141 }, { "text": "and start storing the names of these", "start": 4084.2, "duration": 4.74 }, { "text": "columns in the CSV file itself and in", "start": 4086.24, "duration": 4.44 }, { "text": "fact if any of you have ever opened a", "start": 4088.94, "duration": 4.02 }, { "text": "spreadsheet file before be it in Excel", "start": 4090.68, "duration": 4.439 }, { "text": "Apple Numbers Google spreadsheets or the", "start": 4092.96, "duration": 4.02 }, { "text": "like all odds are you've noticed that", "start": 4095.119, "duration": 4.321 }, { "text": "the first row very frequently is a", "start": 4096.98, "duration": 4.08 }, { "text": "little different it actually is bold", "start": 4099.44, "duration": 3.419 }, { "text": "face sometimes or it actually contains", "start": 4101.06, "duration": 4.199 }, { "text": "the names of those columns the names of", "start": 4102.859, "duration": 4.681 }, { "text": "those attributes below and we can do", "start": 4105.259, "duration": 4.801 }, { "text": "this here and students.csv I don't have", "start": 4107.54, "duration": 4.319 }, { "text": "to just keep assuming that the student's", "start": 4110.06, "duration": 3.9 }, { "text": "name is first and that the student's", "start": 4111.859, "duration": 4.741 }, { "text": "home is second I can explicitly bake", "start": 4113.96, "duration": 5.46 }, { "text": "that information into the file just to", "start": 4116.6, "duration": 4.8 }, { "text": "reduce the probability of mistakes down", "start": 4119.42, "duration": 3.96 }, { "text": "the road I can literally use the first", "start": 4121.4, "duration": 5.16 }, { "text": "row of this file and say name comma home", "start": 4123.38, "duration": 5.279 }, { "text": "so notice that", "start": 4126.56, "duration": 4.32 }, { "text": "name is not literally someone's name and", "start": 4128.659, "duration": 3.901 }, { "text": "home is not literally someone's home it", "start": 4130.88, "duration": 4.319 }, { "text": "is literally the words name and home", "start": 4132.56, "duration": 5.52 }, { "text": "separated by a comma and if I now go", "start": 4135.199, "duration": 5.761 }, { "text": "back into students.pi and don't use CSV", "start": 4138.08, "duration": 5.759 }, { "text": "reader but instead I use a dictionary", "start": 4140.96, "duration": 6.54 }, { "text": "reader I can actually treat my CSV file", "start": 4143.839, "duration": 5.52 }, { "text": "even more flexibly not just for this but", "start": 4147.5, "duration": 4.08 }, { "text": "for other examples too let me do this", "start": 4149.359, "duration": 5.041 }, { "text": "instead of using a CSV reader let me use", "start": 4151.58, "duration": 6.36 }, { "text": "a CSV dict reader which will now iterate", "start": 4154.4, "duration": 6.419 }, { "text": "over the file top to bottom loading in", "start": 4157.94, "duration": 5.759 }, { "text": "each line of text not as a list of", "start": 4160.819, "duration": 5.761 }, { "text": "columns but as a dictionary of columns", "start": 4163.699, "duration": 4.62 }, { "text": "what's nice about this is that it's", "start": 4166.58, "duration": 4.079 }, { "text": "going to give me automatic access now to", "start": 4168.319, "duration": 4.86 }, { "text": "those columns names I'm going to revert", "start": 4170.659, "duration": 5.52 }, { "text": "to just saying for Row in reader and now", "start": 4173.179, "duration": 4.98 }, { "text": "I'm going to append a name and a home", "start": 4176.179, "duration": 4.381 }, { "text": "but how am I going to get access to the", "start": 4178.159, "duration": 5.881 }, { "text": "current rows name and the current rows", "start": 4180.56, "duration": 6.659 }, { "text": "home well earlier I use bracket zero for", "start": 4184.04, "duration": 4.56 }, { "text": "the first and bracket one for the second", "start": 4187.219, "duration": 4.321 }, { "text": "when I was using a reader a reader", "start": 4188.6, "duration": 5.34 }, { "text": "returns lists addict reader or", "start": 4191.54, "duration": 4.92 }, { "text": "dictionary reader returns dictionaries", "start": 4193.94, "duration": 5.88 }, { "text": "one at a time and so if I want to access", "start": 4196.46, "duration": 5.759 }, { "text": "the current Row's name I can say row", "start": 4199.82, "duration": 4.859 }, { "text": "quote unquote name I can say here for", "start": 4202.219, "duration": 5.281 }, { "text": "home row quote-unquote home and I now", "start": 4204.679, "duration": 4.801 }, { "text": "have access to those same values the", "start": 4207.5, "duration": 3.239 }, { "text": "only change I had to make to be clear", "start": 4209.48, "duration": 4.44 }, { "text": "was in my CSV file I had to include on", "start": 4210.739, "duration": 5.701 }, { "text": "the very first row little hints as to", "start": 4213.92, "duration": 4.98 }, { "text": "what these columns are and if I now run", "start": 4216.44, "duration": 4.2 }, { "text": "this code I think it should behave", "start": 4218.9, "duration": 3.42 }, { "text": "pretty much the same python of", "start": 4220.64, "duration": 3.9 }, { "text": "students.pi and indeed we get the same", "start": 4222.32, "duration": 5.76 }, { "text": "sentences but now my code is more robust", "start": 4224.54, "duration": 6.179 }, { "text": "against changes in this data if I were", "start": 4228.08, "duration": 5.28 }, { "text": "to open the CSV file in Excel or Google", "start": 4230.719, "duration": 4.621 }, { "text": "spreadsheets or apple numbers and for", "start": 4233.36, "duration": 3.9 }, { "text": "whatever reason change the columns", "start": 4235.34, "duration": 3.54 }, { "text": "around maybe this is a file that you're", "start": 4237.26, "duration": 2.939 }, { "text": "sharing with someone else and just", "start": 4238.88, "duration": 3.24 }, { "text": "because they decide to sort things", "start": 4240.199, "duration": 3.721 }, { "text": "differently left to right by moving the", "start": 4242.12, "duration": 3.0 }, { "text": "columns around", "start": 4243.92, "duration": 3.239 }, { "text": "previously my code would have broken", "start": 4245.12, "duration": 4.14 }, { "text": "because I was assuming that name is", "start": 4247.159, "duration": 4.5 }, { "text": "always first and home is always second", "start": 4249.26, "duration": 6.06 }, { "text": "but if I did this be it manually in one", "start": 4251.659, "duration": 5.461 }, { "text": "of those programs or here home comma", "start": 4255.32, "duration": 4.08 }, { "text": "name and suppose I reversed all of this", "start": 4257.12, "duration": 4.26 }, { "text": "the home comes first followed by Harry", "start": 4259.4, "duration": 6.24 }, { "text": "the borough then by Ron and then lastly", "start": 4261.38, "duration": 7.62 }, { "text": "Malfoy Manor then Draco notice that my", "start": 4265.64, "duration": 5.28 }, { "text": "file is now completely flipped the First", "start": 4269.0, "duration": 3.239 }, { "text": "Column is now the second and the", "start": 4270.92, "duration": 3.779 }, { "text": "second's the first but I took care to", "start": 4272.239, "duration": 5.101 }, { "text": "update the header of that file the first", "start": 4274.699, "duration": 5.46 }, { "text": "row notice my python code I'm not going", "start": 4277.34, "duration": 4.8 }, { "text": "to touch it at all I'm going to rerun", "start": 4280.159, "duration": 5.281 }, { "text": "python of students.pi and hit enter and", "start": 4282.14, "duration": 6.059 }, { "text": "it still just works and this too is an", "start": 4285.44, "duration": 4.5 }, { "text": "example of like coding defensively like", "start": 4288.199, "duration": 3.601 }, { "text": "what if someone changes your CSV file", "start": 4289.94, "duration": 3.779 }, { "text": "your data file ideally that won't happen", "start": 4291.8, "duration": 4.02 }, { "text": "but even if it does now because I'm", "start": 4293.719, "duration": 4.44 }, { "text": "using a dictionary reader that's going", "start": 4295.82, "duration": 5.46 }, { "text": "to infer from that first row for me what", "start": 4298.159, "duration": 5.52 }, { "text": "the columns are called my code just", "start": 4301.28, "duration": 4.2 }, { "text": "keeps working and so it keeps getting if", "start": 4303.679, "duration": 4.201 }, { "text": "you will better and better", "start": 4305.48, "duration": 5.699 }, { "text": "any questions now on this approach yeah", "start": 4307.88, "duration": 6.0 }, { "text": "what is the importance of online CSV", "start": 4311.179, "duration": 4.321 }, { "text": "file what's the importance of the new", "start": 4313.88, "duration": 3.96 }, { "text": "line in the CSV file it's partly a", "start": 4315.5, "duration": 4.38 }, { "text": "convention in the world of text files we", "start": 4317.84, "duration": 3.839 }, { "text": "humans have just been for decades in the", "start": 4319.88, "duration": 5.22 }, { "text": "habit of storing data line by line it's", "start": 4321.679, "duration": 6.06 }, { "text": "visually convenient it's just easy to", "start": 4325.1, "duration": 4.32 }, { "text": "extract from the file because you just", "start": 4327.739, "duration": 3.721 }, { "text": "look for the new lines so the new line", "start": 4329.42, "duration": 5.04 }, { "text": "just separates some data from some other", "start": 4331.46, "duration": 5.58 }, { "text": "data we could use any other symbol on", "start": 4334.46, "duration": 4.56 }, { "text": "the keyboard but it's just common to hit", "start": 4337.04, "duration": 3.84 }, { "text": "enter to just move the data to the next", "start": 4339.02, "duration": 3.659 }, { "text": "line just a convention", "start": 4340.88, "duration": 4.26 }, { "text": "other questions it seems to be working", "start": 4342.679, "duration": 5.52 }, { "text": "fine if you just have name and home I'm", "start": 4345.14, "duration": 5.28 }, { "text": "wondering what will happen if you want", "start": 4348.199, "duration": 5.46 }, { "text": "to put in more data", "start": 4350.42, "duration": 4.2 }, { "text": "um", "start": 4353.659, "duration": 4.441 }, { "text": "say you wanted to add a house to both", "start": 4354.62, "duration": 5.64 }, { "text": "the name and the home", "start": 4358.1, "duration": 4.079 }, { "text": "sure if you wanted to add the house back", "start": 4360.26, "duration": 3.899 }, { "text": "so if I go in here and add house last", "start": 4362.179, "duration": 5.221 }, { "text": "and I go here and say uh Gryffindor for", "start": 4364.159, "duration": 6.901 }, { "text": "Harry Gryffindor for Ron and Slytherin", "start": 4367.4, "duration": 6.54 }, { "text": "for Draco now I have three columns", "start": 4371.06, "duration": 4.619 }, { "text": "effectively if you will home on the left", "start": 4373.94, "duration": 4.02 }, { "text": "name in the middle house on the right", "start": 4375.679, "duration": 4.621 }, { "text": "each separated by commas with weird", "start": 4377.96, "duration": 4.199 }, { "text": "things like number four comma privet", "start": 4380.3, "duration": 4.32 }, { "text": "Drive still quoted notice if I go back", "start": 4382.159, "duration": 4.441 }, { "text": "to students.pi and I don't change the", "start": 4384.62, "duration": 4.32 }, { "text": "code at all and run python of", "start": 4386.6, "duration": 5.04 }, { "text": "students.pi it still just works and this", "start": 4388.94, "duration": 4.56 }, { "text": "is what's so powerful about a dictionary", "start": 4391.64, "duration": 4.38 }, { "text": "reader it can change over time it can", "start": 4393.5, "duration": 4.98 }, { "text": "have more and more columns your existing", "start": 4396.02, "duration": 4.86 }, { "text": "code is not going to break your code", "start": 4398.48, "duration": 4.259 }, { "text": "would break would be much more fragile", "start": 4400.88, "duration": 3.299 }, { "text": "so to speak if you were making", "start": 4402.739, "duration": 3.301 }, { "text": "assumptions like the first column's", "start": 4404.179, "duration": 3.181 }, { "text": "always going to be named the second", "start": 4406.04, "duration": 3.24 }, { "text": "column's always going to be house things", "start": 4407.36, "duration": 3.9 }, { "text": "will break fast if those assumptions", "start": 4409.28, "duration": 3.3 }, { "text": "break down", "start": 4411.26, "duration": 3.479 }, { "text": "so not a problem in this case", "start": 4412.58, "duration": 4.56 }, { "text": "well let me propose that besides reading", "start": 4414.739, "duration": 4.44 }, { "text": "csvs let's at least take a peek at how", "start": 4417.14, "duration": 4.5 }, { "text": "we might write a csv2 if you're writing", "start": 4419.179, "duration": 4.381 }, { "text": "a program in which you want to store not", "start": 4421.64, "duration": 3.539 }, { "text": "just students names but maybe their", "start": 4423.56, "duration": 3.9 }, { "text": "homes as well in a file how can we keep", "start": 4425.179, "duration": 4.621 }, { "text": "adding to this file let me go ahead and", "start": 4427.46, "duration": 5.279 }, { "text": "delete the contents of students.csv and", "start": 4429.8, "duration": 5.399 }, { "text": "just re-add a single simple row name", "start": 4432.739, "duration": 5.821 }, { "text": "comma home so as to anticipate inserting", "start": 4435.199, "duration": 5.581 }, { "text": "more names and homes into this file and", "start": 4438.56, "duration": 4.38 }, { "text": "then let me go to students.pi and let me", "start": 4440.78, "duration": 4.379 }, { "text": "just start fresh so as to write out data", "start": 4442.94, "duration": 3.36 }, { "text": "this time I'm still going to go ahead", "start": 4445.159, "duration": 3.781 }, { "text": "and import CSV I'm going to go ahead now", "start": 4446.3, "duration": 5.52 }, { "text": "and prompt the user for their name so", "start": 4448.94, "duration": 5.34 }, { "text": "input quote unquote what's your name", "start": 4451.82, "duration": 4.56 }, { "text": "question mark and I'm going to go ahead", "start": 4454.28, "duration": 4.32 }, { "text": "and prompt the user for their home so", "start": 4456.38, "duration": 5.04 }, { "text": "home equals input quote unquote where's", "start": 4458.6, "duration": 6.18 }, { "text": "your home question mark now I'm going to", "start": 4461.42, "duration": 5.16 }, { "text": "go ahead and open the file but this time", "start": 4464.78, "duration": 3.72 }, { "text": "for writing instead of reading as", "start": 4466.58, "duration": 5.119 }, { "text": "follows with open quote unquote", "start": 4468.5, "duration": 5.94 }, { "text": "students.csv I'm going to open in append", "start": 4471.699, "duration": 4.841 }, { "text": "mode so that I keep adding more and more", "start": 4474.44, "duration": 4.14 }, { "text": "students and homes to the file rather", "start": 4476.54, "duration": 3.72 }, { "text": "than just overwriting the entire file", "start": 4478.58, "duration": 3.3 }, { "text": "itself and I'm going to use a variable", "start": 4480.26, "duration": 4.14 }, { "text": "name of file I'm then going to go ahead", "start": 4481.88, "duration": 4.44 }, { "text": "and give myself a variable called writer", "start": 4484.4, "duration": 3.6 }, { "text": "and I'm going to set it equal to the", "start": 4486.32, "duration": 3.78 }, { "text": "return value of another function in the", "start": 4488.0, "duration": 5.34 }, { "text": "CSV module called CSV dot writer and", "start": 4490.1, "duration": 6.42 }, { "text": "that writer function takes as its sole", "start": 4493.34, "duration": 7.02 }, { "text": "argument the file variable there now I'm", "start": 4496.52, "duration": 5.1 }, { "text": "going to go ahead and just do this I'm", "start": 4500.36, "duration": 3.78 }, { "text": "going to say writer dot right row and", "start": 4501.62, "duration": 4.98 }, { "text": "I'm going to pass into right Row the", "start": 4504.14, "duration": 4.8 }, { "text": "line that I want to write to the file", "start": 4506.6, "duration": 4.32 }, { "text": "specifically as a list so I'm going to", "start": 4508.94, "duration": 4.86 }, { "text": "give this a list of name comma home", "start": 4510.92, "duration": 4.2 }, { "text": "which of course are the contents of", "start": 4513.8, "duration": 3.06 }, { "text": "those variables now I'm going to go", "start": 4515.12, "duration": 3.539 }, { "text": "ahead and save the file I'm going to go", "start": 4516.86, "duration": 4.319 }, { "text": "ahead and rerun python of students.pi", "start": 4518.659, "duration": 4.921 }, { "text": "hit enter and what's your name well let", "start": 4521.179, "duration": 4.441 }, { "text": "me go ahead and type in Harry as my name", "start": 4523.58, "duration": 5.159 }, { "text": "and number four", "start": 4525.62, "duration": 7.14 }, { "text": "comma privet Drive enter now notice that", "start": 4528.739, "duration": 6.661 }, { "text": "input itself did have a comma and so if", "start": 4532.76, "duration": 5.1 }, { "text": "I go to my CSV file now notice that it's", "start": 4535.4, "duration": 4.86 }, { "text": "automatically been quoted for me so that", "start": 4537.86, "duration": 3.96 }, { "text": "subsequent reads from this file don't", "start": 4540.26, "duration": 3.66 }, { "text": "confuse that comma with the actual comma", "start": 4541.82, "duration": 4.8 }, { "text": "between Harry and his home well let me", "start": 4543.92, "duration": 3.96 }, { "text": "go ahead and run it a couple of more", "start": 4546.62, "duration": 3.119 }, { "text": "times let me go ahead and rerun python", "start": 4547.88, "duration": 4.2 }, { "text": "of students.pi let me go ahead and input", "start": 4549.739, "duration": 4.92 }, { "text": "this time Ron and his home as the", "start": 4552.08, "duration": 5.22 }, { "text": "borough let's go back to students.csv to", "start": 4554.659, "duration": 4.801 }, { "text": "see what it looks like now we see Ron", "start": 4557.3, "duration": 3.66 }, { "text": "comma the burrow has been added", "start": 4559.46, "duration": 3.3 }, { "text": "automatically to the file and let's do", "start": 4560.96, "duration": 4.8 }, { "text": "one more python of students.pi enter", "start": 4562.76, "duration": 5.76 }, { "text": "let's go ahead and give draco's name and", "start": 4565.76, "duration": 5.04 }, { "text": "his home which would be Malfoy Manor", "start": 4568.52, "duration": 5.159 }, { "text": "enter and if we go back to students.csv", "start": 4570.8, "duration": 4.74 }, { "text": "now we see that Draco is in the file", "start": 4573.679, "duration": 3.841 }, { "text": "itself and the library took care of not", "start": 4575.54, "duration": 3.9 }, { "text": "only writing each of those rows per the", "start": 4577.52, "duration": 3.96 }, { "text": "function's name it also handled the", "start": 4579.44, "duration": 4.5 }, { "text": "escaping so to speak of any strings that", "start": 4581.48, "duration": 4.14 }, { "text": "themselves contain the comma like", "start": 4583.94, "duration": 3.96 }, { "text": "Harry's own home well it turns out", "start": 4585.62, "duration": 3.599 }, { "text": "there's yet another way we we could", "start": 4587.9, "duration": 3.12 }, { "text": "implement this same program without", "start": 4589.219, "duration": 4.081 }, { "text": "having to worry about precisely that", "start": 4591.02, "duration": 3.96 }, { "text": "order again and again and just passing", "start": 4593.3, "duration": 4.14 }, { "text": "in a list it turns out if we're keeping", "start": 4594.98, "duration": 4.38 }, { "text": "track of what's the name and what's the", "start": 4597.44, "duration": 3.36 }, { "text": "home we could use something like a", "start": 4599.36, "duration": 3.42 }, { "text": "dictionary to associate those keys with", "start": 4600.8, "duration": 3.66 }, { "text": "those values so let me go ahead and back", "start": 4602.78, "duration": 3.66 }, { "text": "up and remove these students from the", "start": 4604.46, "duration": 3.84 }, { "text": "file leaving only the header row again", "start": 4606.44, "duration": 4.2 }, { "text": "named comma home and let me go over to", "start": 4608.3, "duration": 4.32 }, { "text": "students.pi and this time instead of", "start": 4610.64, "duration": 4.2 }, { "text": "using CSV writer I'm going to go ahead", "start": 4612.62, "duration": 3.44 }, { "text": "and use", "start": 4614.84, "duration": 3.12 }, { "text": "csv.dictriter which is a dictionary", "start": 4616.06, "duration": 4.0 }, { "text": "writer that's going to open the file in", "start": 4617.96, "duration": 4.02 }, { "text": "much the same way but rather than write", "start": 4620.06, "duration": 5.46 }, { "text": "a row as this list of name comma home", "start": 4621.98, "duration": 6.3 }, { "text": "what I'm now going to do is follows I'm", "start": 4625.52, "duration": 5.88 }, { "text": "going to first output an actual", "start": 4628.28, "duration": 4.74 }, { "text": "dictionary the first key of which is", "start": 4631.4, "duration": 4.2 }, { "text": "Name colon and then the value thereof is", "start": 4633.02, "duration": 3.96 }, { "text": "going to be the name that was typed in", "start": 4635.6, "duration": 3.3 }, { "text": "and I'm going to pass in a key of Home", "start": 4636.98, "duration": 3.42 }, { "text": "quote unquote the value of which of", "start": 4638.9, "duration": 3.36 }, { "text": "course is the home that was typed in but", "start": 4640.4, "duration": 4.38 }, { "text": "with dict writer I do need to give it a", "start": 4642.26, "duration": 4.979 }, { "text": "hint as to the order in which those", "start": 4644.78, "duration": 4.919 }, { "text": "columns are when writing it out so that", "start": 4647.239, "duration": 4.44 }, { "text": "subsequently they could be red even if", "start": 4649.699, "duration": 4.441 }, { "text": "those orderings change let me go ahead", "start": 4651.679, "duration": 4.921 }, { "text": "and pass in field names which is a", "start": 4654.14, "duration": 5.22 }, { "text": "second argument to dictwriter equals and", "start": 4656.6, "duration": 4.98 }, { "text": "then a list of the actual columns that I", "start": 4659.36, "duration": 3.6 }, { "text": "know are in this file which of course", "start": 4661.58, "duration": 4.56 }, { "text": "are name comma home those times in", "start": 4662.96, "duration": 5.04 }, { "text": "quotes because that's indeed the string", "start": 4666.14, "duration": 4.38 }, { "text": "names of the columns so to speak that I", "start": 4668.0, "duration": 4.679 }, { "text": "intend to write to in that file all", "start": 4670.52, "duration": 3.84 }, { "text": "right now let me go ahead and go to my", "start": 4672.679, "duration": 3.601 }, { "text": "terminal window run python of", "start": 4674.36, "duration": 4.319 }, { "text": "students.pi this time I'll type in", "start": 4676.28, "duration": 4.62 }, { "text": "Harry's name again I'll again type in", "start": 4678.679, "duration": 5.52 }, { "text": "number four comma privet Drive", "start": 4680.9, "duration": 6.54 }, { "text": "enter let's now go back to students.csv", "start": 4684.199, "duration": 5.341 }, { "text": "and voila parries back in the file and", "start": 4687.44, "duration": 4.5 }, { "text": "it's properly escaped or quoted I'm sure", "start": 4689.54, "duration": 4.5 }, { "text": "then if we do this again with Ron and", "start": 4691.94, "duration": 4.5 }, { "text": "the burrow and let's go ahead and run it", "start": 4694.04, "duration": 5.34 }, { "text": "one third time with Draco and Malfoy", "start": 4696.44, "duration": 5.36 }, { "text": "Manor enter let's go back to", "start": 4699.38, "duration": 4.5 }, { "text": "students.csv and Via this dictionary", "start": 4701.8, "duration": 4.78 }, { "text": "writer we now have all three of those", "start": 4703.88, "duration": 5.58 }, { "text": "students as well so whereas with CSV", "start": 4706.58, "duration": 6.06 }, { "text": "writer the onus is on us to pass in a", "start": 4709.46, "duration": 5.279 }, { "text": "list of all of the values we want to put", "start": 4712.64, "duration": 4.14 }, { "text": "from left to right with a dictionary", "start": 4714.739, "duration": 4.081 }, { "text": "writer technically they could be in any", "start": 4716.78, "duration": 4.08 }, { "text": "order in the dictionary in fact I could", "start": 4718.82, "duration": 5.1 }, { "text": "just have correctly done this passing in", "start": 4720.86, "duration": 5.46 }, { "text": "home followed by name but it's a", "start": 4723.92, "duration": 4.38 }, { "text": "dictionary and so the ordering in this", "start": 4726.32, "duration": 3.899 }, { "text": "case does not matter so long as the key", "start": 4728.3, "duration": 3.18 }, { "text": "is there and the value is there and", "start": 4730.219, "duration": 3.421 }, { "text": "because I have passed in field names as", "start": 4731.48, "duration": 4.679 }, { "text": "the second argument to dict writer it", "start": 4733.64, "duration": 4.92 }, { "text": "ensures that the library knows exactly", "start": 4736.159, "duration": 5.161 }, { "text": "which column contains name or home", "start": 4738.56, "duration": 4.2 }, { "text": "respectively", "start": 4741.32, "duration": 3.899 }, { "text": "are there any questions now on", "start": 4742.76, "duration": 4.8 }, { "text": "dictionary reading dictionary writing or", "start": 4745.219, "duration": 4.801 }, { "text": "csvs more generally", "start": 4747.56, "duration": 5.46 }, { "text": "India any specifics the specific", "start": 4750.02, "duration": 5.46 }, { "text": "situation for me to use a single", "start": 4753.02, "duration": 4.639 }, { "text": "quotation or double quotation because", "start": 4755.48, "duration": 4.92 }, { "text": "after the print we use a single", "start": 4757.659, "duration": 5.681 }, { "text": "quotation to represent the key of the", "start": 4760.4, "duration": 6.12 }, { "text": "dictionary but after the", "start": 4763.34, "duration": 5.399 }, { "text": "reading or writing we use the double", "start": 4766.52, "duration": 3.9 }, { "text": "quotation", "start": 4768.739, "duration": 4.321 }, { "text": "it's a good question in Python you can", "start": 4770.42, "duration": 5.1 }, { "text": "generally use double quotes or you can", "start": 4773.06, "duration": 4.02 }, { "text": "use single quotes and it doesn't matter", "start": 4775.52, "duration": 3.78 }, { "text": "you should just be self-consistent so", "start": 4777.08, "duration": 4.139 }, { "text": "that stylistically your code looks the", "start": 4779.3, "duration": 4.5 }, { "text": "same all throughout sometimes though it", "start": 4781.219, "duration": 4.921 }, { "text": "is necessary to alternate if you're", "start": 4783.8, "duration": 4.08 }, { "text": "already using double quotes as I was", "start": 4786.14, "duration": 4.32 }, { "text": "earlier for a long F string but inside", "start": 4787.88, "duration": 5.04 }, { "text": "that F string I was interpolating the", "start": 4790.46, "duration": 4.199 }, { "text": "values of some variables using curly", "start": 4792.92, "duration": 3.9 }, { "text": "braces and those variables were", "start": 4794.659, "duration": 5.161 }, { "text": "dictionaries and in order to index into", "start": 4796.82, "duration": 5.82 }, { "text": "a dictionary you use square brackets and", "start": 4799.82, "duration": 4.44 }, { "text": "then quotes but if you're already using", "start": 4802.64, "duration": 3.36 }, { "text": "double quotes out here you should", "start": 4804.26, "duration": 4.439 }, { "text": "generally use single quotes here or vice", "start": 4806.0, "duration": 5.4 }, { "text": "versa but otherwise I'm in the habit of", "start": 4808.699, "duration": 4.261 }, { "text": "using double quotes everywhere others", "start": 4811.4, "duration": 2.94 }, { "text": "are in the habit of using single quotes", "start": 4812.96, "duration": 3.779 }, { "text": "everywhere it only matters sometimes if", "start": 4814.34, "duration": 6.24 }, { "text": "one might be confused for the other", "start": 4816.739, "duration": 6.601 }, { "text": "other questions on dictionary uh writing", "start": 4820.58, "duration": 5.579 }, { "text": "or reading uh yeah I did my question is", "start": 4823.34, "duration": 6.48 }, { "text": "can we use multiple CSV files in any", "start": 4826.159, "duration": 4.861 }, { "text": "program", "start": 4829.82, "duration": 3.48 }, { "text": "absolutely you can use as many CSV files", "start": 4831.02, "duration": 3.719 }, { "text": "as you want and it's just one of the", "start": 4833.3, "duration": 3.78 }, { "text": "formats that you can use to save data", "start": 4834.739, "duration": 5.541 }, { "text": "other questions on csvs or file IO", "start": 4837.08, "duration": 6.599 }, { "text": "thanks for taking my question uh so when", "start": 4840.28, "duration": 6.1 }, { "text": "you're reading from the file the um you", "start": 4843.679, "duration": 6.781 }, { "text": "had the um as a dictionary you had the", "start": 4846.38, "duration": 5.7 }, { "text": "fields called", "start": 4850.46, "duration": 2.94 }, { "text": "um couldn't you just call it when you're", "start": 4852.08, "duration": 2.579 }, { "text": "reading could couldn't you just call the", "start": 4853.4, "duration": 3.06 }, { "text": "row in the previous version of the of", "start": 4854.659, "duration": 5.401 }, { "text": "the students uh Pi file", "start": 4856.46, "duration": 6.719 }, { "text": "um when you're reading the uh when", "start": 4860.06, "duration": 4.2 }, { "text": "you're reading each row you are", "start": 4863.179, "duration": 6.261 }, { "text": "splitting out the um the fields by name", "start": 4864.26, "duration": 5.18 }, { "text": "yeah so when you're appending to the uh", "start": 4870.26, "duration": 4.2 }, { "text": "to the students list can you just call", "start": 4872.239, "duration": 4.201 }, { "text": "the uh for row and reader", "start": 4874.46, "duration": 4.86 }, { "text": "students.append row rather than", "start": 4876.44, "duration": 5.46 }, { "text": "uh rather than naming each of the fields", "start": 4879.32, "duration": 5.96 }, { "text": "oh very clever uh short answer yes", "start": 4881.9, "duration": 7.5 }, { "text": "insofar as dick to reader returns one", "start": 4885.28, "duration": 6.879 }, { "text": "dictionary at a time when you Loop over", "start": 4889.4, "duration": 4.62 }, { "text": "it rho is already going to be a", "start": 4892.159, "duration": 4.5 }, { "text": "dictionary so yes you could actually get", "start": 4894.02, "duration": 4.5 }, { "text": "away with doing this and the effect", "start": 4896.659, "duration": 4.56 }, { "text": "would really be the same in this case", "start": 4898.52, "duration": 4.98 }, { "text": "good observation how about one more", "start": 4901.219, "duration": 4.801 }, { "text": "question on csvs", "start": 4903.5, "duration": 6.48 }, { "text": "yeah when reading in csvs from my past", "start": 4906.02, "duration": 6.84 }, { "text": "work with data a lot of things can go", "start": 4909.98, "duration": 4.62 }, { "text": "wrong I don't know if it's a fair", "start": 4912.86, "duration": 3.48 }, { "text": "question that you can answer in a few", "start": 4914.6, "duration": 3.96 }, { "text": "sentences but are there any best", "start": 4916.34, "duration": 6.299 }, { "text": "practices to double check that sort of", "start": 4918.56, "duration": 7.02 }, { "text": "no mistakes occurred it's a really good", "start": 4922.639, "duration": 5.221 }, { "text": "question and I would say in general if", "start": 4925.58, "duration": 5.099 }, { "text": "you're using code to generate the csvs", "start": 4927.86, "duration": 5.7 }, { "text": "and to read the csvs and you're using a", "start": 4930.679, "duration": 4.5 }, { "text": "good Library theoretically nothing", "start": 4933.56, "duration": 4.38 }, { "text": "should go wrong it should be 100 correct", "start": 4935.179, "duration": 6.361 }, { "text": "if the libraries are 100 correct you and", "start": 4937.94, "duration": 5.279 }, { "text": "I tend to be the problem like when you", "start": 4941.54, "duration": 4.679 }, { "text": "let a human touch the CSV or when Excel", "start": 4943.219, "duration": 4.681 }, { "text": "or apple numbers or some other tools", "start": 4946.219, "duration": 3.601 }, { "text": "involved that might not be aligned with", "start": 4947.9, "duration": 3.96 }, { "text": "your code's expectations things then yes", "start": 4949.82, "duration": 5.46 }, { "text": "can break the goal really sometimes", "start": 4951.86, "duration": 5.22 }, { "text": "honestly the solution is manual fixes", "start": 4955.28, "duration": 4.379 }, { "text": "you go in and fix the CSV or you have a", "start": 4957.08, "duration": 4.2 }, { "text": "lot of error checking or you have a lot", "start": 4959.659, "duration": 3.901 }, { "text": "of try except just to tolerate mistakes", "start": 4961.28, "duration": 4.56 }, { "text": "in the data but generally I would say if", "start": 4963.56, "duration": 4.32 }, { "text": "you're using CSV or any file format", "start": 4965.84, "duration": 4.56 }, { "text": "internally to a program to both read and", "start": 4967.88, "duration": 4.38 }, { "text": "write it you shouldn't have concerns", "start": 4970.4, "duration": 3.66 }, { "text": "there you and I the humans are the", "start": 4972.26, "duration": 3.84 }, { "text": "problem uh generally speaking and not", "start": 4974.06, "duration": 4.079 }, { "text": "the programmers the users of those files", "start": 4976.1, "duration": 4.32 }, { "text": "instead all right allow me to propose", "start": 4978.139, "duration": 4.741 }, { "text": "that we leave csvs behind but to note", "start": 4980.42, "duration": 4.02 }, { "text": "that they're not the only file format", "start": 4982.88, "duration": 3.9 }, { "text": "you you can use in order to read or", "start": 4984.44, "duration": 3.9 }, { "text": "write data in fact they're a popular", "start": 4986.78, "duration": 4.379 }, { "text": "format as is just raw text files dot txt", "start": 4988.34, "duration": 5.1 }, { "text": "files but you can store data really any", "start": 4991.159, "duration": 4.381 }, { "text": "way that you want we've just picked csvs", "start": 4993.44, "duration": 3.779 }, { "text": "because it's representative of how you", "start": 4995.54, "duration": 3.659 }, { "text": "might read and write from a file and do", "start": 4997.219, "duration": 3.841 }, { "text": "so in a structured way where you can", "start": 4999.199, "duration": 4.201 }, { "text": "somehow have multiple Keys multiple", "start": 5001.06, "duration": 4.619 }, { "text": "values all in the same file without", "start": 5003.4, "duration": 3.66 }, { "text": "having to resort to what would be", "start": 5005.679, "duration": 4.02 }, { "text": "otherwise known as a binary file so a", "start": 5007.06, "duration": 4.679 }, { "text": "binary file is a file that's really just", "start": 5009.699, "duration": 4.201 }, { "text": "zeros and ones and they can be laid out", "start": 5011.739, "duration": 4.081 }, { "text": "in any pattern you might want", "start": 5013.9, "duration": 3.96 }, { "text": "particularly if you want to store not", "start": 5015.82, "duration": 4.5 }, { "text": "textual information but maybe graphical", "start": 5017.86, "duration": 5.7 }, { "text": "or audio or video information as well so", "start": 5020.32, "duration": 5.16 }, { "text": "it turns out that python is really good", "start": 5023.56, "duration": 3.84 }, { "text": "when it comes to having libraries for", "start": 5025.48, "duration": 3.84 }, { "text": "really everything and in fact there's a", "start": 5027.4, "duration": 4.259 }, { "text": "popular Library called pillow that", "start": 5029.32, "duration": 5.64 }, { "text": "allows you to navigate image files as", "start": 5031.659, "duration": 5.881 }, { "text": "well and to perform operations on image", "start": 5034.96, "duration": 4.62 }, { "text": "files you can apply filters a lot", "start": 5037.54, "duration": 4.86 }, { "text": "Instagram you can animate them as well", "start": 5039.58, "duration": 4.68 }, { "text": "and so what I thought we'd do is leave", "start": 5042.4, "duration": 3.72 }, { "text": "behind behind text files for now and", "start": 5044.26, "duration": 3.899 }, { "text": "Tackle one more demonstration this time", "start": 5046.12, "duration": 5.64 }, { "text": "focusing on this particular library and", "start": 5048.159, "duration": 5.881 }, { "text": "image files instead so let me propose", "start": 5051.76, "duration": 4.86 }, { "text": "that we go over here to vs code and", "start": 5054.04, "duration": 4.679 }, { "text": "create a program ultimately that creates", "start": 5056.62, "duration": 3.9 }, { "text": "an animated gif these things are", "start": 5058.719, "duration": 3.841 }, { "text": "everywhere nowadays in the form of memes", "start": 5060.52, "duration": 3.78 }, { "text": "and animations and stickers and the like", "start": 5062.56, "duration": 4.079 }, { "text": "in an animated gif is really just an", "start": 5064.3, "duration": 4.379 }, { "text": "image file that has multiple images", "start": 5066.639, "duration": 5.04 }, { "text": "inside of it and your computer or your", "start": 5068.679, "duration": 5.401 }, { "text": "phone shows you those images one after", "start": 5071.679, "duration": 4.921 }, { "text": "another sometimes on an endless loop", "start": 5074.08, "duration": 4.86 }, { "text": "again and again and so long as there's", "start": 5076.6, "duration": 4.26 }, { "text": "enough images it creates the illusion of", "start": 5078.94, "duration": 3.9 }, { "text": "Animation because your mind and mind", "start": 5080.86, "duration": 4.08 }, { "text": "kind of fills in the gaps visually and", "start": 5082.84, "duration": 3.839 }, { "text": "just assumes that if something is moving", "start": 5084.94, "duration": 4.199 }, { "text": "even though you're only seeing one frame", "start": 5086.679, "duration": 4.98 }, { "text": "per second or some sequence thereof it", "start": 5089.139, "duration": 4.381 }, { "text": "looks like an animation so it's like a", "start": 5091.659, "duration": 4.381 }, { "text": "simplistic version of a video file well", "start": 5093.52, "duration": 4.679 }, { "text": "let me propose that we start with maybe", "start": 5096.04, "duration": 5.099 }, { "text": "a couple of uh costumes from another", "start": 5098.199, "duration": 4.801 }, { "text": "popular programming language and let me", "start": 5101.139, "duration": 3.721 }, { "text": "go ahead and open up my first cost team", "start": 5103.0, "duration": 3.96 }, { "text": "here number one so suppose here that", "start": 5104.86, "duration": 3.72 }, { "text": "this is a costume or really just a", "start": 5106.96, "duration": 3.199 }, { "text": "static image here", "start": 5108.58, "duration": 3.659 }, { "text": "costume1.jif and it's just a static", "start": 5110.159, "duration": 4.661 }, { "text": "picture of a cat no movement at all let", "start": 5112.239, "duration": 5.361 }, { "text": "me go ahead now and open up a second one", "start": 5114.82, "duration": 5.28 }, { "text": "costume2.jif that looks a little bit", "start": 5117.6, "duration": 4.539 }, { "text": "different notice and I'll go back and", "start": 5120.1, "duration": 4.5 }, { "text": "forth this cat's legs are a little bit", "start": 5122.139, "duration": 4.381 }, { "text": "aligned differently so that this was", "start": 5124.6, "duration": 5.22 }, { "text": "version one and this was version two now", "start": 5126.52, "duration": 4.74 }, { "text": "these cats come from a programming", "start": 5129.82, "duration": 3.359 }, { "text": "language from MIT called scratch that", "start": 5131.26, "duration": 3.84 }, { "text": "allows you very graphically to animate", "start": 5133.179, "duration": 4.261 }, { "text": "all this and more but we'll use just", "start": 5135.1, "duration": 5.76 }, { "text": "these two static images costume one and", "start": 5137.44, "duration": 5.88 }, { "text": "costume two to create our own animated", "start": 5140.86, "duration": 4.56 }, { "text": "gif that after this you could text to a", "start": 5143.32, "duration": 4.379 }, { "text": "friend or message them much like any", "start": 5145.42, "duration": 5.1 }, { "text": "meme online well let me propose that we", "start": 5147.699, "duration": 5.101 }, { "text": "create this animated gif not by just", "start": 5150.52, "duration": 3.9 }, { "text": "using some off-the-shelf program that we", "start": 5152.8, "duration": 3.359 }, { "text": "downloaded but by writing our own code", "start": 5154.42, "duration": 4.219 }, { "text": "let me go ahead and run code of", "start": 5156.159, "duration": 4.621 }, { "text": "costumes.pi and create our very own", "start": 5158.639, "duration": 4.6 }, { "text": "program that's going to take as input to", "start": 5160.78, "duration": 5.04 }, { "text": "or even more image file files and then", "start": 5163.239, "duration": 5.101 }, { "text": "generate an animated gif from them by", "start": 5165.82, "duration": 4.26 }, { "text": "essentially creating this animated gif", "start": 5168.34, "duration": 4.56 }, { "text": "by toggling back and forth endlessly", "start": 5170.08, "duration": 5.34 }, { "text": "between those two images well how am I", "start": 5172.9, "duration": 4.02 }, { "text": "going to do this well let's assume that", "start": 5175.42, "duration": 2.759 }, { "text": "this will be a program called", "start": 5176.92, "duration": 4.08 }, { "text": "costumes.pi that expects uh two command", "start": 5178.179, "duration": 4.98 }, { "text": "line arguments the names of the files", "start": 5181.0, "duration": 4.08 }, { "text": "the individual costumes that we want to", "start": 5183.159, "duration": 4.141 }, { "text": "animate back and forth so to do that I'm", "start": 5185.08, "duration": 3.659 }, { "text": "going to import sys so that we", "start": 5187.3, "duration": 4.379 }, { "text": "ultimately have access to sys.org V I'm", "start": 5188.739, "duration": 4.741 }, { "text": "then from this pillow Library going to", "start": 5191.679, "duration": 3.96 }, { "text": "import support for images specifically", "start": 5193.48, "duration": 6.12 }, { "text": "so from pil import image capital i as", "start": 5195.639, "duration": 6.301 }, { "text": "per the library's documentation now I'm", "start": 5199.6, "duration": 3.66 }, { "text": "going to give myself an empty list", "start": 5201.94, "duration": 3.42 }, { "text": "called images just so I have a list in", "start": 5203.26, "duration": 4.14 }, { "text": "which to store one or two or or more of", "start": 5205.36, "duration": 4.68 }, { "text": "these images and now let me do this", "start": 5207.4, "duration": 7.56 }, { "text": "for each argument in sis.org V I'm going", "start": 5210.04, "duration": 6.42 }, { "text": "to go ahead and create a new image", "start": 5214.96, "duration": 5.179 }, { "text": "variable set it equal to this image", "start": 5216.46, "duration": 7.5 }, { "text": "dot open function passing in ARG now", "start": 5220.139, "duration": 6.401 }, { "text": "what is this doing I proposing that", "start": 5223.96, "duration": 3.9 }, { "text": "eventually I want to be able to run", "start": 5226.54, "duration": 3.78 }, { "text": "python of costumes.pi and then as", "start": 5227.86, "duration": 3.92 }, { "text": "command line arguments specify", "start": 5230.32, "duration": 4.08 }, { "text": "costume1.jif space costume two dot shift", "start": 5231.78, "duration": 4.0 }, { "text": "so I want to take in those file names", "start": 5234.4, "duration": 4.68 }, { "text": "from the command line as my arguments so", "start": 5235.78, "duration": 5.64 }, { "text": "what am I doing here well I'm iterating", "start": 5239.08, "duration": 5.22 }, { "text": "over sys.org V all of the words in my", "start": 5241.42, "duration": 4.98 }, { "text": "command line arguments I'm creating a", "start": 5244.3, "duration": 3.899 }, { "text": "variable called image and I'm passing to", "start": 5246.4, "duration": 3.96 }, { "text": "this function image.open from the pillow", "start": 5248.199, "duration": 4.801 }, { "text": "library that specific argument and that", "start": 5250.36, "duration": 4.62 }, { "text": "library is essentially going to open", "start": 5253.0, "duration": 4.26 }, { "text": "that image in a way that gives me a lot", "start": 5254.98, "duration": 4.02 }, { "text": "of functionality for manipulating it", "start": 5257.26, "duration": 4.08 }, { "text": "like animating now I'm going to go ahead", "start": 5259.0, "duration": 3.3 }, { "text": "and", "start": 5261.34, "duration": 6.299 }, { "text": "append to my images list that particular", "start": 5262.3, "duration": 7.56 }, { "text": "image and that's it so this Loop's", "start": 5267.639, "duration": 3.721 }, { "text": "purpose in life is just to iterate over", "start": 5269.86, "duration": 3.06 }, { "text": "the command line arguments and open", "start": 5271.36, "duration": 4.56 }, { "text": "those images using this Library the last", "start": 5272.92, "duration": 5.219 }, { "text": "line is pretty straightforward I'm going", "start": 5275.92, "duration": 3.96 }, { "text": "to say this I'm going to grab the first", "start": 5278.139, "duration": 3.54 }, { "text": "of those images which is going to be in", "start": 5279.88, "duration": 4.44 }, { "text": "my list at location zero and I'm going", "start": 5281.679, "duration": 5.46 }, { "text": "to save it to disk that is I'm going to", "start": 5284.32, "duration": 4.8 }, { "text": "save this file now in the past when we", "start": 5287.139, "duration": 4.56 }, { "text": "use csvs or text files I had to do the", "start": 5289.12, "duration": 4.559 }, { "text": "file opening I had to do the file", "start": 5291.699, "duration": 4.081 }, { "text": "writing maybe even the closing I don't", "start": 5293.679, "duration": 3.601 }, { "text": "need to do that with this Library the", "start": 5295.78, "duration": 3.72 }, { "text": "pillow library takes care of the opening", "start": 5297.28, "duration": 4.5 }, { "text": "the closing and the saving for me by", "start": 5299.5, "duration": 4.56 }, { "text": "just calling save I'm going to call this", "start": 5301.78, "duration": 3.899 }, { "text": "save function and just to leave space", "start": 5304.06, "duration": 3.48 }, { "text": "because I have a number of arguments to", "start": 5305.679, "duration": 3.241 }, { "text": "pass I'm going to move to another line", "start": 5307.54, "duration": 3.72 }, { "text": "so it fits I'm going to pass in the name", "start": 5308.92, "duration": 4.88 }, { "text": "of the file that I want to create", "start": 5311.26, "duration": 5.04 }, { "text": "costume.jif that will be the name of my", "start": 5313.8, "duration": 4.72 }, { "text": "animated gif I'm going to tell this", "start": 5316.3, "duration": 5.7 }, { "text": "library to save all of the frames that I", "start": 5318.52, "duration": 5.52 }, { "text": "pass to it so the First costume the", "start": 5322.0, "duration": 3.659 }, { "text": "second costume and even more if I gave", "start": 5324.04, "duration": 4.26 }, { "text": "them I'm going to then append to this", "start": 5325.659, "duration": 6.361 }, { "text": "first image the image is zero uh the", "start": 5328.3, "duration": 5.1 }, { "text": "following images", "start": 5332.02, "duration": 3.9 }, { "text": "equals this list of images and this is a", "start": 5333.4, "duration": 4.5 }, { "text": "bit clever but I'm going to do this I", "start": 5335.92, "duration": 4.14 }, { "text": "want to append the next image there", "start": 5337.9, "duration": 5.339 }, { "text": "images one and now I want to specify a", "start": 5340.06, "duration": 5.52 }, { "text": "duration of 200 milliseconds for each of", "start": 5343.239, "duration": 4.681 }, { "text": "these frames and I want this to Loop", "start": 5345.58, "duration": 4.8 }, { "text": "forever and if you specify Loop equals", "start": 5347.92, "duration": 5.04 }, { "text": "zero that is Time Zero it means it's", "start": 5350.38, "duration": 4.799 }, { "text": "just not going to Loop a finite number", "start": 5352.96, "duration": 4.199 }, { "text": "of times but an infinite number of times", "start": 5355.179, "duration": 4.761 }, { "text": "instead and I need to do one other thing", "start": 5357.159, "duration": 6.961 }, { "text": "recall that sys.org V contains not just", "start": 5359.94, "duration": 6.219 }, { "text": "the words I typed after my program's", "start": 5364.12, "duration": 4.86 }, { "text": "name but what else does sys.org v", "start": 5366.159, "duration": 5.161 }, { "text": "contain if you think back to our", "start": 5368.98, "duration": 4.679 }, { "text": "discussion of command line arguments", "start": 5371.32, "duration": 5.64 }, { "text": "what else is insist.orgv besides the", "start": 5373.659, "duration": 5.401 }, { "text": "words I'm about to type like costume one", "start": 5376.96, "duration": 5.88 }, { "text": "dot GIF and costume two yeah so we'll", "start": 5379.06, "duration": 5.76 }, { "text": "actually get in that their original name", "start": 5382.84, "duration": 4.44 }, { "text": "of the program we want to run the", "start": 5384.82, "duration": 4.56 }, { "text": "costume set pie indeed we'll get the", "start": 5387.28, "duration": 4.32 }, { "text": "original name of the program costumes.pi", "start": 5389.38, "duration": 3.359 }, { "text": "in this case which is not a gif", "start": 5391.6, "duration": 3.9 }, { "text": "obviously so remember that using slices", "start": 5392.739, "duration": 5.761 }, { "text": "in Python we can do this if sys.orgv is", "start": 5395.5, "duration": 5.28 }, { "text": "a list and we want to get a slice of", "start": 5398.5, "duration": 3.84 }, { "text": "that list everything after the first", "start": 5400.78, "duration": 4.68 }, { "text": "element we can do one colon which says", "start": 5402.34, "duration": 6.42 }, { "text": "start at location one not zero and take", "start": 5405.46, "duration": 5.16 }, { "text": "a slice all the way to the end so give", "start": 5408.76, "duration": 4.08 }, { "text": "me everything except the first thing in", "start": 5410.62, "duration": 4.019 }, { "text": "that list which to McKenzie's point is", "start": 5412.84, "duration": 3.839 }, { "text": "the name of the program", "start": 5414.639, "duration": 4.441 }, { "text": "now if I haven't made any mistakes let's", "start": 5416.679, "duration": 4.56 }, { "text": "see what happens I'm going to run python", "start": 5419.08, "duration": 4.139 }, { "text": "of costumes.pi and now I'm going to", "start": 5421.239, "duration": 3.781 }, { "text": "specify the two images that I want to", "start": 5423.219, "duration": 3.44 }, { "text": "animate so", "start": 5425.02, "duration": 5.28 }, { "text": "costume1.jif and costume2.gif", "start": 5426.659, "duration": 5.98 }, { "text": "what is the code now going to do well to", "start": 5430.3, "duration": 4.439 }, { "text": "recap we're using the sys library to", "start": 5432.639, "duration": 3.6 }, { "text": "access those command line arguments", "start": 5434.739, "duration": 3.661 }, { "text": "we're using the pillow library to treat", "start": 5436.239, "duration": 4.561 }, { "text": "those files as images and with all the", "start": 5438.4, "duration": 3.6 }, { "text": "functionality that comes with that", "start": 5440.8, "duration": 3.72 }, { "text": "Library I'm using this images list just", "start": 5442.0, "duration": 4.679 }, { "text": "to accumulate all of these images one at", "start": 5444.52, "duration": 4.5 }, { "text": "a time from the command line and in line", "start": 5446.679, "duration": 4.56 }, { "text": "seven through nine I'm just using a loop", "start": 5449.02, "duration": 4.26 }, { "text": "to iterate over all of them and just add", "start": 5451.239, "duration": 4.321 }, { "text": "them to this list after opening them", "start": 5453.28, "duration": 4.68 }, { "text": "with the library and the last step which", "start": 5455.56, "duration": 3.9 }, { "text": "is really just one line of code broken", "start": 5457.96, "duration": 3.779 }, { "text": "onto three so that it all fits I'm going", "start": 5459.46, "duration": 4.62 }, { "text": "to save the first image but I'm asking", "start": 5461.739, "duration": 5.281 }, { "text": "the library to append this other image", "start": 5464.08, "duration": 4.86 }, { "text": "to it as well not bracket zero but", "start": 5467.02, "duration": 3.6 }, { "text": "bracket one and if I had more I could", "start": 5468.94, "duration": 4.199 }, { "text": "express those as well I want to save all", "start": 5470.62, "duration": 4.44 }, { "text": "of these files together I want to pause", "start": 5473.139, "duration": 4.861 }, { "text": "200 milliseconds a fifth of a second in", "start": 5475.06, "duration": 5.099 }, { "text": "between each frame and I want it to Loop", "start": 5478.0, "duration": 6.239 }, { "text": "infinitely many times so now if I cross", "start": 5480.159, "duration": 7.201 }, { "text": "my fingers as always hit enter", "start": 5484.239, "duration": 5.221 }, { "text": "nothing bad happened and that's almost", "start": 5487.36, "duration": 5.1 }, { "text": "always a good thing let me now run code", "start": 5489.46, "duration": 7.56 }, { "text": "of costumes dot Jif to open up in vs", "start": 5492.46, "duration": 7.08 }, { "text": "code the final image and what I think I", "start": 5497.02, "duration": 6.119 }, { "text": "should see is a very happy cat and", "start": 5499.54, "duration": 5.46 }, { "text": "indeed so now we've seen not only that", "start": 5503.139, "duration": 3.661 }, { "text": "we can read and write files be it", "start": 5505.0, "duration": 4.08 }, { "text": "textually we can read and now write", "start": 5506.8, "duration": 4.74 }, { "text": "files that are binary zeros and ones", "start": 5509.08, "duration": 4.079 }, { "text": "we've just scratched the surface this is", "start": 5511.54, "duration": 3.78 }, { "text": "using the library called pillow But", "start": 5513.159, "duration": 3.601 }, { "text": "ultimately this is going to give us the", "start": 5515.32, "duration": 3.18 }, { "text": "ability to read and write files however", "start": 5516.76, "duration": 4.379 }, { "text": "we want so we've now seen that via file", "start": 5518.5, "duration": 4.44 }, { "text": "i o we can manipulate not just textual", "start": 5521.139, "duration": 4.321 }, { "text": "files be it txt files or csvs but even", "start": 5522.94, "duration": 4.739 }, { "text": "binary files as well in this case they", "start": 5525.46, "duration": 4.199 }, { "text": "happen to be images but if we dived in", "start": 5527.679, "duration": 3.96 }, { "text": "deeper we could find explore audio and", "start": 5529.659, "duration": 4.261 }, { "text": "video and so much more all by way of", "start": 5531.639, "duration": 3.781 }, { "text": "these simple Primitives this ability", "start": 5533.92, "duration": 4.799 }, { "text": "somehow to read and write files that's", "start": 5535.42, "duration": 7.16 }, { "text": "it for now we'll see you next time", "start": 5538.719, "duration": 3.861 } ]