пожалуйста, возвращайтесь позднее
пожалуйста, возвращайтесь позднее
>> PARLANTE: All right, hey, everybody. All right [INDISTINCT] a lot of people working away on this one. It's our requirement that you finish like all the problems on this one, I'm just hoping that if you could get like, some of them. What I'd like to do, is I want to do another quick lecture section then I want to break our time for, you know, the nice long exercise at the end. And you're welcome to keep working on the list problems if you want, but this last exercise, once we have file reading, then could begin to look like a real program. And it's going to involve — it's going to sum up all the material we've talked about, lists and strings also, put it all together and that'll be the last thing for today. So, the last day I was sure to show you is the HashTable or also called the dictionary. It's a very useful data structure, it's built-in to Python; it's pretty easy to use. So, the delimiter character for a dictionary is the curly brace. So here, I'll create one. I'll say D is equal to left curly brace, right curly brace. I'll just create an empty one. And the way the dictionary works — and I've got a little piece of art there from the hand out at the top — is you can think of it as a — it's said to contain key value bindings. For each key, it can look up that value very quickly. So, the way that works in Python is I'll say, under the key A, I would like to store the string alpha, and under the string O — I'm just going to make the same example I have in that little picture there — I'll store omega, and under the key G, I'll store gamma, put it there on my [INDISTINCT]. So, what HashTable does is you always talk to it in terms of keys. You say, "Dictionary, please store this key," and it will store whatever. And then later on, when you try and retrieve by key — this is the one thing that HashTables are fast at — it can retrieve via key in constant time. It's just as fast as you can imagine, it's very quick at key retrieval. So, for example, if I say, okay dictionary — and I — in Python, the way it works is we just use the square brackets. When I use the square bracket on the left, I was storing a value in. So, that series of three assignments, that builds exactly this picture of the dictionary. So, you can think of the dictionary as what has a set of keys and each — for each key it points to some value. If I want to look — do a look up, I would say, well instead of — just don't put it on the left hand side of an equal. So, if I just say D of A, it just returns the value, oh alpha. Now, not to belay with the point too much, that's the one thing that dictionaries are fast at. You could put 10 million keys in this dictionary, and yet for a particular one, you could call it up and it would call it up in just a few cycles on the machine. It's very, very fast at key look up, that's the one thing that it does. So, let me show you, you know, a few more features you could do with dictionaries. So, obviously, you can store stuff in, you could use the square right to get stuff out. If I refer to a key that is not in there, I say, "All right dictionary, what do you have for key value X?" What I get is actually an error, a key error so that's a — it's a long puzzle. I think Python is trying to be sort of consistent with the list here, that if I said list, square bracket like a thousand and there is no thousand — you know, it would've given an error. So, I think there's sort of an attempt to be kind of consistent with what square bracket means.