© Distribution of this video is restricted by its owner
00:00 | What do you think? Fiddling with morning, e. So, |
|
|
00:17 | things, uh, work our find victories, and with that comes with |
|
|
00:25 | much e thing class, uh, from with, uh, with |
|
|
00:48 | uh, a, uh, material you're, you know, your life |
|
|
01:06 | . It's more than a eso, obviously wait, sign meditations and matter |
|
|
01:21 | from becoming, um uh etc. , um, and you're thinking a |
|
|
01:38 | , uh um So basically, uh e o uh, mhm any any |
|
|
02:21 | questions on and, uh uh, . You know, a to get |
|
|
03:02 | the morning. Uh huh. So e uh, Mhm. Yeah. |
|
|
04:06 | . Okay. And of course, , if anybody has a, |
|
|
04:15 | situation they wanted just because we're all after the class. Okay, |
|
|
04:24 | so with that, let's try to started. No. So what we've |
|
|
04:39 | so far is, uh is the the python and program we've done so |
|
|
04:47 | , Except input from the user. your tithe programs is what's your |
|
|
04:53 | Your tithe? Of course. That , that is an important medium of |
|
|
05:03 | a moment, uh, on the . But of course, in |
|
|
05:11 | um, you know, that's not program. So most of the time |
|
|
05:16 | computer program manipulates file. In it z u a e a But |
|
|
05:40 | essentially the military spies. Okay, miss pictures. So? So that's |
|
|
05:50 | . And so today we're going to with files everything you have done. |
|
|
05:55 | , uh, e any questions so ? Yeah. Yes. So |
|
|
06:22 | uh um so in fight on basically, you open a file. |
|
|
06:33 | It's not complicated opening you need from on right away. And then |
|
|
06:42 | we'll see that you open it slightly if you have to read it slightly |
|
|
06:48 | when you're to write it. But than that is the same idea, |
|
|
06:53 | important thing is you open the file now you want to write to it |
|
|
06:58 | do something with it. And how you do that once you you use |
|
|
07:04 | command like this? Uh, on from then on, you don't need |
|
|
07:18 | , uh, a finally have another , flunking man and in fact, |
|
|
07:25 | maybe input from the user. So the way from the user. |
|
|
07:31 | yeah, Bush is that when you're farm, we don't have to refer |
|
|
07:34 | find all the time. You just a valuable in this case. Find |
|
|
07:39 | way. That is all you need processing. Defy. Okay, so |
|
|
07:47 | three ways off doing this. one is enough to ways of opening |
|
|
07:56 | file. There are other combinations of , but basically, you open a |
|
|
08:01 | to read it. And that's what just a normal looking by. Con |
|
|
08:09 | . Open it our means. You're of this. Read from the |
|
|
08:13 | And, uh, W is that purpose is to write to the |
|
|
08:19 | And then once you're done with it's good to clothe whether you are |
|
|
08:35 | it with you whether you open the for reading or writing. Okay. |
|
|
08:43 | , uh, don't worry about the part right now. Let's just focus |
|
|
08:49 | reading and writing. So what can do? You have a file You |
|
|
08:53 | it on. What can you do you're reading you? Can you open |
|
|
09:00 | this? Our option? Then of you can read from it. You |
|
|
09:04 | to write it, It won't let write it. If you try toe |
|
|
09:08 | it. Writing overwrite. Any kind a right will not work. And |
|
|
09:13 | a You know, you say open on, uh, something. |
|
|
09:22 | uh, a fine is not Uh, s so basically with a |
|
|
09:32 | with a read makes sense that, know, you can read from the |
|
|
09:36 | . The file has to be Otherwise, there's nothing to read |
|
|
09:40 | Right, Um, if you open the right option, then you cannot |
|
|
09:46 | from it. You can only Okay. And then, of |
|
|
09:50 | you can write. You can The file could be empty. |
|
|
09:55 | uh, because, for example, start writing is useful. If the |
|
|
10:01 | has something in, it is a . Um what about this surprise? |
|
|
10:14 | said you want, uh, uh, you know, a story |
|
|
10:24 | . There is no five point holdings your computer. What should the |
|
|
10:37 | Yeah, this is you want to ? Uh huh. And it doesn't |
|
|
10:43 | you a a a so easy so . Yeah. So now the next |
|
|
10:56 | is, where are these files that read and write from? So, |
|
|
11:07 | , so I think you all know are lots of files on your |
|
|
11:13 | So how well organized? A very list off your computers you know, |
|
|
11:22 | Yeah, all of us. And performers on some farmers and, |
|
|
11:33 | pretty much eso for this, but basically, you're, you |
|
|
11:48 | some kind of off. Yeah, , the trash can Someone. |
|
|
12:07 | Yeah. What is that? a uh, Yeah. A |
|
|
13:00 | Uh huh. E a e E Uh, thank you. |
|
|
14:18 | a mhm. Okay. And make A Okay, So Okay, a |
|
|
15:20 | e a mhm e o Okay. Yeah, e o If it's |
|
|
16:31 | I can just say Uh huh. huh. I can just say |
|
|
16:44 | Yeah, as long as that file in the same folder where the program |
|
|
16:52 | running from, Right. So that , if it's looking for, I |
|
|
16:58 | just put this name and anybody can that program and run it as long |
|
|
17:02 | they have a file locally available there everything should be fine. But you |
|
|
17:11 | also say suppose, uh, this , um let's say, man, |
|
|
17:20 | , uh, here is where the is running. Yeah, but And |
|
|
17:31 | is where? Here. So what I say? Fun. Will it |
|
|
17:42 | if I'm running from here? If say here dark text eso if see |
|
|
18:16 | . Mhm. Yeah, So I My programs are in one folder on |
|
|
18:34 | data I want to access is off folder off the parent folder of where |
|
|
18:42 | programs are. So if I'm running program, I say they're gonna |
|
|
18:54 | No. Can I make How can make it work? I wonder if |
|
|
18:59 | go a little higher and yes, . Um what I'm trying todo could |
|
|
19:13 | the whole name, but for the one. Yeah, so slash I |
|
|
19:19 | todo Basically, if I dio slash Normally, I'm here, And if |
|
|
19:32 | in the path of the way I'm the bath I put a slash |
|
|
19:36 | I'm a wow. Okay, So I from here I say dark dart |
|
|
19:44 | your lord, that's it's OK, from here, now I'm looking at |
|
|
19:49 | folder up, So basically, the , dark location picks you up So |
|
|
20:04 | on here, e z, you a you right. But this was |
|
|
20:29 | , a a just, uh do start slash dot Uh, All |
|
|
21:01 | Uh uh, Okay. A this and the windows with S o e |
|
|
21:36 | A. Yeah. A questions. . Files or you should be looking |
|
|
22:05 | files on your computer. Okay, let's see. So it's OK, |
|
|
22:18 | should we spend more time on All right? We'll do some exercises |
|
|
22:25 | a bit. Okay. So let's forward. Um, right. So |
|
|
22:35 | do we read? Um, this nothing new we already saw. You |
|
|
22:41 | say file handle is you could open , and then there's an actual command |
|
|
22:47 | Read. So this is how you read from a file? Read a |
|
|
22:51 | file. Okay, so you're saying is five. Handle, Dr. |
|
|
22:56 | . It's the, um, the call on. Duh. And you |
|
|
23:07 | just print it. So when you something like that, when you |
|
|
23:11 | read, and when somebody's on the forward, the entire final becomes a |
|
|
23:18 | and content is the strength that contains entire file. Okay. And, |
|
|
23:28 | , there is a second way of . It is more than one. |
|
|
23:31 | here you can also read like So the difference instead of read, |
|
|
23:38 | have read lines, okay. And , um, this returns The lines |
|
|
23:44 | a list now, and each element the list is a string. That's |
|
|
23:50 | line in the file. Yeah. right. Let's see if any of |
|
|
23:59 | works. Yeah. Yeah. Yes. Yeah. Mhm. |
|
|
24:34 | Uh huh. Yeah. Mhm. . Yeah. Yeah, it's just |
|
|
25:00 | a sale. Yeah. All Away. Right. Is this gonna |
|
|
25:11 | ? I said open. Find Breed. Hi. Is it likely |
|
|
25:19 | work? Oh, I'm sorry. this zone work? Because you can |
|
|
25:22 | it? Yes. Uh, Oh, okay. Yeah. E |
|
|
25:56 | is what I was trying to Um, yeah, The screen doesn't |
|
|
26:08 | . Okay. Yeah. All You can still see it. Will |
|
|
26:13 | work? Okay, maybe. Yeah. Thank you. Yeah. |
|
|
26:35 | . Uh huh. Oh, Ms. Saying I'm missing some code |
|
|
26:43 | . I don't know where they disappeared second. Yeah. Oh, |
|
|
27:07 | So I'm missing coats. Thank Alright, it'll work now, so |
|
|
27:17 | you can see there's actually a file Z, you can see. |
|
|
27:27 | there is a file with that name my desktop. Will that work? |
|
|
27:50 | . Mhm. That was uh Now you can't read the symbol that |
|
|
27:59 | like it And, uh, even I have a file by that name |
|
|
28:07 | my desktop. So let's try something and that didn't work. So |
|
|
28:17 | Let's work. Have changed the read write and change the name of the |
|
|
28:25 | . Yes. Is there a fine that? No, it doesn't |
|
|
28:34 | So it's trite. It's a I didn't do much. But what's |
|
|
28:43 | difference? Sorry. Yes. So can find a find, right? |
|
|
28:54 | get to that in a minute. , it doesn't know. It doesn't |
|
|
29:02 | to find a way. It is on in the Oh, Okay. |
|
|
29:08 | no, the the reason it didn't the read waas that you can try |
|
|
29:21 | on your if you like, is I had the I had a file |
|
|
29:29 | Constitution. That text on my Uh uh, When does if you |
|
|
29:44 | click, look at properties on any , it will give you the full |
|
|
29:50 | in the directory where the file Okay, so I'm doing that |
|
|
29:55 | Um mhm. So it tells me the file that I was talking about |
|
|
30:11 | , uh, mhm. True Okay. Okay. If I typed |
|
|
30:48 | correctly, let's see if this does better and it's happy now it's again |
|
|
30:56 | with the read option. But once put the full file name, |
|
|
31:00 | it Z like it. And as shortcut, I can just right click |
|
|
31:05 | something and find the file them if can see the file in a |
|
|
31:09 | Okay. So now yeah. What we do with this? What can |
|
|
31:22 | dio content? So we want to it. Okay, so it Z |
|
|
31:35 | huh uh, okay. Can content anybody? Remember FB maybe read |
|
|
32:01 | That's it? Yeah, right. done with this statement. Right. |
|
|
32:15 | what content or FB content. So should it dio? It should print |
|
|
32:24 | Constitution or whatever is in the file . So you'll find the file. |
|
|
32:30 | , in this case has advertising, you might see other things, but |
|
|
32:40 | , it worked. So it za , this file is from, um |
|
|
32:49 | an e book from something called Project , which is trying to get a |
|
|
32:54 | off the literature and playing open Okay, so it's that simple. |
|
|
33:01 | just a string. Content is just string. So everything you learned about |
|
|
33:06 | and everything applies how you can do of those things with fights. |
|
|
33:12 | so let's try the other side the cause waas read lines. Is that |
|
|
33:20 | ? Have petered. Read lines. what will it now? What is |
|
|
33:24 | content? Uh huh. It's what with them. Sorry. Right for |
|
|
33:40 | . I'm not saying what is what in. I'm just gonna What is |
|
|
33:45 | type off? Okay. Breath. . Okay. I'm gonna uh |
|
|
33:57 | What I'm going to get? Mhm. It's a list. What's |
|
|
34:12 | that list? Yes, actually. you can froth a You use a |
|
|
34:32 | called red Lines then, uh, can, um Hey, you |
|
|
34:41 | you you read one line of time strength. Okay. So, |
|
|
34:49 | Yeah. I mean, let's What else can we do with |
|
|
34:55 | We can say far. Um, . Uh huh. No. |
|
|
35:21 | Okay. But it's just gonna dio , yeah, okay. It's not |
|
|
35:31 | to do anything until I put a . Know what it's going to |
|
|
35:41 | Uh, sorry. Yeah, that's . Uh huh. All right. |
|
|
35:55 | , Sorry. Infinite loop. What doing for the content is a list |
|
|
36:05 | strength. What is far? String content? Looping over. Mhm. |
|
|
36:12 | a far look. So So Your list is a eyes is basically |
|
|
36:20 | list of strength. So what I to do, I don't know if |
|
|
36:24 | have done it. Try is I to go What? Every line and |
|
|
36:28 | something. So if you say form something in something, it will go |
|
|
36:32 | every line, right? So That's Yeah, each good questions. |
|
|
36:44 | each element. Uh, okay. we did f petered. Red lines |
|
|
36:54 | now, content is a list that knew. We check already. |
|
|
37:04 | about So now what's it gonna What this going to dio? So you're |
|
|
37:15 | a follow up? You're running through element of the list. Each one |
|
|
37:19 | a line, and you're gonna print line, so you should get the |
|
|
37:23 | thing. You'll get the file printed one line at a time. |
|
|
37:33 | so let's see. Uh, so doing something like that. So let |
|
|
37:43 | um it's a little bit. Mhm thing. Is this program |
|
|
38:37 | Thank you. Counting the number of . How many lines are in the |
|
|
38:43 | . S. Constitution? Domain isn't it? Wasn't that required rating |
|
|
38:51 | some course? Yeah, 100. of millions. Does anybody read the |
|
|
39:00 | ? Now you're busy. Okay, . Too long. Has anybody seen |
|
|
39:07 | Constitution? You just you know, assume something like a Constitution must be |
|
|
39:16 | long. So let's find out if runs this 1989 98 lines. |
|
|
39:25 | uh, this is not a Uh uh. Let's see if I |
|
|
39:38 | a copy of the Constitution. Constitution very tiny, tiny little book you |
|
|
39:43 | read in about an hour, so not very long. Okay, So |
|
|
39:48 | 9 98 lines is also not really . Because, uh, so And |
|
|
39:56 | any case, 1998 38. So any questions so far? Uh |
|
|
40:12 | , so let's get back, Yeah, yeah, yeah, |
|
|
40:31 | Yes. A few things were born . If the five doesn't exist, |
|
|
40:35 | get an error. We saw an when we try to open the file |
|
|
40:39 | the wrong path name and so Um, it's always read as a |
|
|
40:44 | , whether it's a number just like port, whether a or something, |
|
|
40:50 | that is a strange You know how do the type conversion. If you're |
|
|
40:53 | for a number and you should close files when you're done now, the |
|
|
40:59 | thing is eso it's similar you You this. The only difference is that |
|
|
41:11 | use the right call this year instead our, uh then you can |
|
|
41:23 | just like a string. You can the right function instead of really interesting |
|
|
41:29 | available on that content will go on in the file a 10 end of |
|
|
41:35 | file if it's not empty. uh uh uh on then you close |
|
|
41:42 | , okay? Eso Few things about of the file already exists. It |
|
|
41:48 | be rewritten if you open a It's everything is gone in that |
|
|
41:57 | Um, again, you can only you can write to a file of |
|
|
42:02 | strength. So if you want to something else No, really problem. |
|
|
42:11 | again, you closed the files at end. All right, So, |
|
|
42:19 | , now you have all the Um, uh, Andi remind you |
|
|
42:26 | . One more. Um, so look at this program. This the |
|
|
42:32 | as what we did before. Let's that file handle is an handle. |
|
|
42:36 | open file and read the lines. , this is what we did |
|
|
42:42 | And anybody knows what this call A line is a string. So |
|
|
42:55 | , that's not a trick question. you use a split function on a |
|
|
42:59 | , it blocks up, it makes , ah, list of sub strings |
|
|
43:03 | each sub string is award in the . So if you have if you |
|
|
43:10 | this this, uh, as the and as I suppose this was a |
|
|
43:18 | and you get airline dark split your list will consist off a list. |
|
|
43:25 | one is one of these words. . Uh, so can you do |
|
|
43:35 | exercise? Yeah. At least think it for five minutes. I think |
|
|
43:45 | have all the tools to do You should do it now. You'll |
|
|
43:47 | . What? So I'm good Is the question clear? Yeah, |
|
|
43:57 | . Yeah. On. And let's the file is a 11? |
|
|
44:14 | anything that, uh, car? . Yeah. Uh uh, |
|
|
44:47 | Anybody done? Uh huh. Right it's It's We've pretty much seen most |
|
|
44:57 | it already. Uh huh. Uh . Uh huh. Yes, you |
|
|
45:48 | . For testing, you can create guard txt file just tagged by |
|
|
45:53 | Anything you want. Yeah, and . Yea, thanks. Uh |
|
|
46:37 | Yeah. Oh, Any questions and . Oh, Okay. Yeah. |
|
|
47:43 | okay? Oh, mhm, Yeah. See the file open statement |
|
|
48:25 | needs a strength. So here I've the string in the program. Doesn't |
|
|
48:30 | in. Obviously the the whole name have to be in the open |
|
|
48:35 | The string name can be assigned or can be read from import mhm. |
|
|
48:58 | , but mhm e o something you don't know. I have to do |
|
|
49:50 | problem. It's this mhm boots. , yes, yeah. Z |
|
|
50:28 | a you know? Ouch. Are any questions about a Okay, we're |
|
|
51:06 | . I'm going Thio just post one that works, and you can look |
|
|
51:14 | it, but it you know, . So basically, um, it |
|
|
51:29 | you know, it's really, hash off everything we saw. We've |
|
|
51:34 | this before. How do you import ? Yeah. So you input the |
|
|
51:42 | off a file and put the string the file the same way we've done |
|
|
51:47 | . Read every line of the have a for loop that goes over |
|
|
51:53 | loathe. You set the count to , and then you use this call |
|
|
52:05 | convert this line, um, in , my list where my list is |
|
|
52:11 | , list off words each. It's strength towards. And then you trade |
|
|
52:18 | this my list. And if it's call to string, which is what |
|
|
52:25 | read, then you implement the counter your friend the counter. In the |
|
|
52:34 | , anybody followed this doable easy, when you see the solution. |
|
|
52:45 | Yeah. Yes. Okay. Right. So, uh, |
|
|
52:58 | So, Okay, so what is lines? Is a list off |
|
|
53:09 | Okay, on duh airline. The off the lines is is list Airline |
|
|
53:17 | a strength. Okay, Every line the file is now a strength. |
|
|
53:25 | , uh, my list is, , list off strength. So each |
|
|
53:38 | in my list is you know, sentence as let's go back, |
|
|
53:43 | If the sentence is this one is line in the file is this Then |
|
|
53:49 | my list is a list. First is right. Second is a thirties |
|
|
53:53 | and so on. So, um , my list is a list consisting |
|
|
54:00 | word in that time. Yeah, . Any other questions? Let me |
|
|
54:10 | if it doesn't run. Okay. can continue that at later, and |
|
|
54:19 | have more assignments on that for the class. I don't want to cover |
|
|
54:23 | more topic today, which is, , on de. So we're gonna |
|
|
54:28 | on. Unless there's a question. , so the this is just a |
|
|
54:35 | off. Everything that we saw there another call. We don't see |
|
|
54:39 | You can call, read line and lines and read line. Actually, |
|
|
54:44 | the while one line at a Okay? So, yeah. All |
|
|
54:52 | , so next topic is dictionaries. the so far in this class |
|
|
55:04 | um, basically simple data types, , uh, on. Then we've |
|
|
55:14 | less than strength. One thing common , uh, on s, |
|
|
55:29 | dictionaries is a how did a type we're going to see and, |
|
|
55:38 | the they're a little different Now, think about it. Why do we |
|
|
55:42 | something? Uh, eso Suppose you thio make a list off student |
|
|
55:56 | You want to record student names and calling card number? So, |
|
|
56:07 | uh huh. A za missed every . Right. So, uh, |
|
|
56:33 | immediate access A. It's just a of It's a same thing when you |
|
|
57:01 | , uh, when you're in a or a restaurant. We saw these |
|
|
57:05 | e what's have meanings. And that's real world dictionary. I think there's |
|
|
57:43 | mapping. The idea here is mapping key to a value In the first |
|
|
57:49 | here, the key is a student , and the value is the sugar |
|
|
57:55 | number. Second case, The key the item, and the value is |
|
|
57:59 | price. Here. The third case word in the dictionary is the |
|
|
58:04 | and its meaning is the value. , so dictionary is a mapping. |
|
|
58:10 | , between kids and values. Keys immutable type. Anybody remember? Mutable |
|
|
58:23 | strongest, mutable and immutable. you know. Thank you. You |
|
|
58:33 | , uh, you can that Uh, yes. So he has |
|
|
58:47 | be is an immutable can be a , a name, integer anything and |
|
|
58:58 | value can be anything, including a . So that's the idea. Off |
|
|
59:05 | . How to eso Again? Let's a visual feeling off. What a |
|
|
59:11 | looks like eso in. You can creating a dictionary. This call creates |
|
|
59:20 | empty dictionary. You can just say equals. Uh, empty. You |
|
|
59:25 | the curly braces here that's been ordered and then you start adding items and |
|
|
59:34 | o You know, some of us that dictionary, because sometimes I'm not |
|
|
59:41 | with these acronyms people are using and or email or whatnot. So you |
|
|
59:47 | like that. So you're basically you know, l o l means |
|
|
59:52 | out. Uh, so each of you can add these items. |
|
|
59:57 | That makes sense. Yes. Clear . Um, right. So the |
|
|
60:11 | braces in this case is to create dictionary. So I think if you're |
|
|
60:21 | , ah, single elements like you can use exactly this format. |
|
|
60:28 | is no curly braces. If you're eso lower down, you say a |
|
|
60:43 | toe creation, and you can put like this. Okay, so, |
|
|
60:57 | , e just first entered d d and then l o l. And |
|
|
61:06 | that's not relevant. This is these the mapping that are in there somewhere |
|
|
61:11 | additional. Okay, so that's a difference with yeah, or one of |
|
|
61:17 | differences. So, other ways you use the dictionary is, uh, |
|
|
61:34 | your program, you can have put list off your employees and, |
|
|
61:39 | are there index numbers and their names . So, in this case, |
|
|
61:45 | kidney is the employee number. And value is the name. Okay. |
|
|
61:52 | the way you use it And once run the statement, then if |
|
|
61:58 | um uh huh execute that statement, it will return the name of them |
|
|
62:05 | that matches that particular entry, which in this case, Uh, that's |
|
|
62:18 | think there's a typo here just And that seems like a natter. |
|
|
62:23 | ? So what, you're written Pat , right? So, yeah, |
|
|
62:29 | is a fix that I think I playing around with. The idea is |
|
|
62:35 | it's a mapping. That does not the Social Security numbers on. |
|
|
62:41 | uh, that doesn't mean that, know, the company has one million |
|
|
62:48 | . If you put a random number , then you'll get a A |
|
|
62:54 | It will not take on anything. , um, just hang on a |
|
|
63:07 | . You cannot just directly do it way, but you can just We'll |
|
|
63:12 | . So the question is work If put in the, uh um, |
|
|
63:19 | is one way, but you can can go backwards. We just see |
|
|
63:25 | a minute. Yes, Mhm. more examples. So you get |
|
|
63:39 | uh, idea off kind of things can dio. He has a price |
|
|
63:47 | . You added an elementary. So way to think off it is that |
|
|
63:52 | consists off these items that were added again, they were added in a |
|
|
63:57 | order, but that that's not um, uh, really important. |
|
|
64:06 | Okay, try to work through the statement. What should it written? |
|
|
64:17 | . Uh huh. It was about ? What would be the impact off |
|
|
64:31 | the second statements? What will be ? I think this one this picture |
|
|
64:45 | for after the first statement, what be the picture after the second |
|
|
64:49 | Will it be the same? yeah. So one off those items |
|
|
64:56 | changed to fight 12. Okay, these are the dictionaries are mutable. |
|
|
65:05 | can change things inside the dictionary. . Uh, north ordered. |
|
|
65:12 | And, uh, you can add we've seen that you already have a |
|
|
65:19 | . You can just say this and will add a new value. You |
|
|
65:23 | modify a value, and this we seen before. You can delete values |
|
|
65:30 | can delete. This is a uh, values is not. It's |
|
|
65:36 | key value pair you can elite a by just saying the lead in case |
|
|
65:42 | key. Oh, any questions so ? Yeah, He Okay, so |
|
|
66:09 | dictionary of methods, just like with for less. We have methods or |
|
|
66:16 | . You can, um, ask keys in the dictionary and it will |
|
|
66:23 | a view off the keys. you're saying what? What is a |
|
|
66:27 | ? Let's get to that in a . Values will return a view off |
|
|
66:33 | values so you can say, Give all the keys you give me all |
|
|
66:37 | values that you value. What? that works. Um, and same |
|
|
66:47 | the items. Um, uh Yeah. Right. So this is |
|
|
66:58 | you, um yeah, another way getting the value in the value associated |
|
|
67:09 | a key. We'll get to this a minute. The reason we're saying |
|
|
67:15 | Ah, view off the let's say dictionary has, you know, |
|
|
67:21 | way use it. This may be little confusing. So you confused |
|
|
67:37 | Let's move on. Hopefully it gets . Uh huh. Um, |
|
|
67:47 | So just look at this for a . What is this program doing? |
|
|
67:59 | this is one off the things that talked about the keys will return a |
|
|
68:06 | off the keys in the dictionary for key in inventory darkies. You do |
|
|
68:16 | , you have a key year And this is the key on. |
|
|
68:20 | is the value. Okay. Um , so the when you say in |
|
|
68:33 | or keys, it returns all the , but the order is not |
|
|
68:39 | Okay, So when you're running this phone loop, even though you entered |
|
|
68:47 | items you know in the apples, , oranges and pears, you're not |
|
|
68:52 | to get those in that order. , so it's not a list, |
|
|
68:56 | this has a specific order E o . What Order E. S. |
|
|
69:08 | that's why it's a view and not list. If you want to |
|
|
69:12 | uh, this this view toe a , then you can cast into a |
|
|
69:21 | . You make it a can. is a simple example. But another |
|
|
69:43 | off saying that you'll go through this print. I got you know, |
|
|
69:49 | key. It'll say say bananas, maps to value 3. 12 and |
|
|
69:53 | loop will go through it, printing this information in some arbitrary order. |
|
|
70:05 | it Z Oh, yeah, So is a shortcut. Uh, it's |
|
|
70:16 | same thing we did before for Employees actually goes through the keys even |
|
|
70:23 | we don't specifically say go. So you say for something in the |
|
|
70:28 | go through things essentially a short cut what we did before. So this |
|
|
70:34 | you so often that you don't even to say specifically what the keys |
|
|
70:41 | Yeah. Yeah. So you can check, uh, if ah particular |
|
|
70:55 | exists in a dictionary and with the function again, it's checking the |
|
|
71:01 | If the particular key is there or by, uh, so the why |
|
|
71:10 | reason you want toe do this is if you for this, uh, |
|
|
71:18 | . If you trying Thio, and then so you say X equal |
|
|
71:32 | employees and string around it, it matter if you can't read it. |
|
|
71:37 | nonsense number. What's gonna happen? you're trying to say give me the |
|
|
71:44 | compared thio for the key and, , on if that doesn't happen, |
|
|
71:53 | doesn't exist. Then you're going to another off, right? So because |
|
|
71:57 | value is not there. You don't others in your program, so you |
|
|
72:01 | first check. If you're not sure this employee, you can say if |
|
|
72:05 | employees is in there, then give something on, uh, s so |
|
|
72:11 | don't have to execute this statement. , uh, um, so another |
|
|
72:23 | thing he would dictionaries is, um , so we have a dictionary. |
|
|
72:30 | are up, up, up, down. The opposite of up is |
|
|
72:34 | . Opposite of writer's strong opposite of is false. Okay, so now |
|
|
72:39 | say Alias equals opposite. Okay, you rename the dictionary, give it |
|
|
72:45 | name, and, uh um, this should be straightforward if you |
|
|
72:54 | um, alias is opposite. They're . So you will get true. |
|
|
73:00 | can check it. The the interesting is, you said Alias, |
|
|
73:10 | Equals left. So instead, off , uh, you make it left |
|
|
73:18 | then you say print opposites, What will it print you see, |
|
|
73:43 | a U. S. A. , uh, a baby is |
|
|
73:54 | Is that identical thing? Then you through, you change one of the |
|
|
74:01 | . Yes. Wrong. Left now cycles. If in the beginning, |
|
|
74:06 | you said print opposites are flying, would have been wrong for sure, |
|
|
74:10 | at this point, will it be or will it be wrong, |
|
|
74:19 | So, um, it will be . So the assignment when you assign |
|
|
74:29 | have a dictionary when you and the of the dictionary is opposite. And |
|
|
74:36 | you say Alias equals opposite it just the same dictionary, another name, |
|
|
74:42 | doesn't make a copy. So when make a change to any one of |
|
|
74:47 | , the other Uh okay, so actually somewhat unusual with python. But |
|
|
74:56 | if you really want to make a have a dictionary. You want to |
|
|
74:59 | a copy and you wanna mess weather you know you want do this because |
|
|
75:05 | will be changing both of them at same time. And, uh |
|
|
75:13 | eso there is ah col College And, uh, eso If you |
|
|
75:22 | this, then this dictionary is And if you do that, then |
|
|
75:30 | will be a new dictionary, which identical, at least in the |
|
|
75:35 | and that will be a copy and you have to use the copy called |
|
|
75:41 | just the simple assignment. The difference you have a copy physical opposite start |
|
|
75:46 | , which is an explicit copy. . Just just an assignment. |
|
|
76:00 | so any questions? Any other So, for for checking the values |
|
|
76:09 | can one ways. Of course you , uh, you know, there's |
|
|
76:14 | separate calls to there's a different function check for the value. I don't |
|
|
76:19 | what the call is, but off course you can go through the |
|
|
76:25 | . You can always do a four and go through the dictionary and |
|
|
76:29 | you know, like, check if match or not. But there is |
|
|
76:33 | is a call to do that, . As with everything else, there's |
|
|
76:35 | call. I'm Okay. Any questions dictionaries? You eso I'm gonna skip |
|
|
76:48 | and look at this for two This is going to be a part |
|
|
76:52 | your class. Work on first? , eso Just if you have any |
|
|
76:57 | right now. Uh, uh Okay. Okay. Mhm. |
|
|
77:19 | okay. We'll stop for today. , uh, you know, try |
|
|
77:23 | to work on this. Um, that will if you can do |
|
|
77:27 | then you followed everything so far Yeah. Uh huh. Uh |
|
|
77:38 | Okay. Thank you. Yeah. . Yes, of course that you |
|
|
78:08 | within the hour. Mhm. Yeah, yeah, A Okay s |
|
|
79:02 | you have, uh, String. , thank you, e. You |
|
|
79:23 | to split this one? So what return is a list? Yeah. |
|
|
79:37 | it will return a list. Each of it is a strength on. |
|
|
79:43 | basically using the blank as a So any time there's an empty |
|
|
79:52 | Yeah. Yeah. So this is , uh yeah. So, |
|
|
80:07 | right. So that's the airline. split. So a line is a |
|
|
80:12 | . If airline was this, I , I'm just not using the correct |
|
|
80:16 | correct or syntax. If this was line. Ah, Ndure dead. |
|
|
80:24 | X equals airline dark split. So will be this list, which has |
|
|
80:30 | is the first element artist, The government and us The third element? |
|
|
80:40 | , it is the split. Yeah. Thank |
|