‫Lecturer: Hi, within this lecture
‫we are going to learn about dictionaries.
‫So we have learned about arrays
‫and in arrays we have ordered collections, right?
‫We have indexes.
‫So we have learned about sets and in sets,
‫we didn't have ordered collections,
‫we had unordered collections,
‫but we had unique elements.
‫And inside of dictionaries,
‫we will have key value pairings.
‫So we are going to have a key,
‫and we are going to have an assigned value
‫of that key inside of a dictionary.
‫So maybe you cannot imagine what it looks like right now
‫but you will understand why and when
‫we are going to use dictionaries
‫once we do the example.
‫So suppose that you have a favorite movie array
‫one more time,
‫but rather than just saving the favorite movies
‫you want to save the respective directors
‫of that movies as well.
‫For example, rather than just saying Pulp Fiction,
‫you have to say Pulp Fiction,
‫and Pulp Fiction is directed by Quentin Tarantino.
‫Okay, so how do you do that?
‫You can put those values into two separate arrays, right?
‫You can have one where my favorite directors array over here
‫in which you will list your favorite directors
‫like Quentin Tarantino, Guy Richie,
‫and then you may create another array
‫in which you put the respective values for those directors.
‫Like you can go like this, Tarantino, and then Guy Richie,
‫and I can create another array just like this.
‫And in the first element I can say Pulp Fiction,
‫and in the second element I can say
‫Lock, Stock and Two Smoking Barrels.
‫And this would work, but it wouldn't be as efficient
‫as a dictionary, because I can go like this in a dictionary,
‫Pulp Fiction and Tarantino.
‫So all you have to do is just put a column
‫between key and the value.
‫So the first one is key
‫and the second one is the value of that key.
‫For Guy Richie I'm going to go Lock, Stock,
‫and hit a column and I will say Guy Richie, for example.
‫So let us do one more example over here, The Dark Knight,
‫and this will be directed by Christopher Nolan.
‫Okay, Christopher Nolan.
‫So this is a dictionary.
‫It's very similar to array
‫but you put a column between key and values.
‫So if you do my favorite directors, as you can see
‫this is now a string to string dictionary.
‫And key is string and value is string as well.
‫Of course it could be string to integer,
‫integer to string, it doesn't matter.
‫So can I do this?
‫Of course I can, because dictionaries do not have indexes.
‫You could have gone for,
‫my favorite director is Pulp Fiction,
‫and that would be okay.
‫So rather than giving indexes, I give keys in here.
‫So when I provide a key, it will return the value to me.
‫So I can go for the Dark Knight, for example
‫it'll just say Christopher Nolan
‫as you might see on the right hand side.
‫So this is how you work with a dictionary, okay?
‫This is how you create,
‫this is how you operate with dictionaries.
‫For example, I can go and say that Pulp Fiction
‫is not Tarantino anymore, it's Quentin Tarantino, okay?
‫And this will change the value of the Tarantino.
‫This is now Quentin Tarantino.
‫If I go over and just print my favorite directors dictionary
‫I will see that the Pulp Fiction is directed
‫by Quentin Tarantino rather than Tarantino.
‫So I can actually change the values afterwards.
‫Furthermore, I can do the same thing
‫in the arrays as well, right?
‫So let's go to one of the arrays.
‫Okay, let's go to number array here.
‫So where do we have a number array?
‫Yeah, here in the my number array.
‫Can I do something like that?
‫My number, first element, I mean the zero.
‫Okay, so this is one, right?
‫If I run this, I will see one on the right hand side.
‫But what if I want to change this to 15?
‫Can I do that?
‫Of course I can.
‫If I run this, it will show me
‫that my number zero is now 15.
‫And if I call my number array zero
‫one more time over here, then I will see 15.
‫So this is basically the same thing as coming here
‫and saying my favorite director is Pulp Fiction
‫is not anymore Tarantino is Quentin Tarantino.
‫Okay, so how do you append a value
‫like we did in the array section?
‫If you do my favorite directors that append,
‫you will see that there is no method
‫that is append or insert or put.
‫You will have to do like this.
‫You will say that my favorite directors,
‫and let me do Seven Samurai for example, okay?
‫And the director of the Seven Samurai
‫will be Akira Kurisowa.
‫So the Seven Samurai is now equal to Akira Kurisowa.
‫Okay? So if I call my favorite directors one more time,
‫so let me cut this print and put it over here,
‫and let me run this.
‫And as you can see now, I see my value
‫in my favorite directors dictionary.
‫So that's how you append a new value
‫and that's how you change the value over here as well.
‫So this is again, a key value pairing structure.
‫And as I said before, of course
‫this wouldn't have to be string to string.
‫You can create something like my dictionary.
‫And in this dictionary just suppose
‫that you're building a fitness app.
‫So running is 100 calories,
‫swimming is 200 calories
‫and basketball is 300 calories, okay?
‫You can go like this.
‫If you just call my dictionary run for example.
‫So as you can see, even here
‫it's a string to int dictionary.
‫So I can just say my dictionary run
‫and if I run this, I will get 100 here.
‫So this is good, right?
‫We're going to use dictionaries a lot
‫when we build apps as well.
‫As you can see, these are not ordered collections
‫like arrays because it doesn't need to be ordered anyway
‫because we are not using indexes over here,
‫we are just calling every value by their keys.
‫So we have key value pairings in dictionaries.
‫So we have learned a lot, right?
‫So we have learned about arrays.
‫And if you want to have ordered objects
‫like structured objects, use arrays.
‫If you want to call them by index, use arrays.
‫If you want to have every element uniquely in your set
‫in your data set, then use sets.
‫If you want to have a key value pairing
‫then you should go for dictionaries.
‫And again, we are gonna see a lot
‫of examples regarding those structures
‫and don't worry about it.
‫So let us stop here.
‫Following the next lecture
‫we're going to start learning about loops.