 You might recall that when we were talking about lists, I used a term known as a collection and As you can already guess from sort of the title of the slide We're now looking at multi-dimensional lists big fancy five dollar word but what we're really referring to is this idea of nested Lists and the way I like to think about this is what we're talking about is a collection of Collections the idea goes if we think about it once again when we're dealing with a list a list operates by having some index in some element at that particular index remember the index is just representing sort of one big magic variable and then specifically The point in memory for this variable where to go in particular But when we're dealing with nested lists, we're dealing with a lot of data and a really great way to think about this is How would I represent a table if we look at sort of this table of miles between each one of these cities? You know to get from Chicago to Atlanta is roughly speaking 714 miles give or take You know how could I take this data that I have going on and represent it as a variable or as a list? Well, the way we can think about that is once again if we think about this as a list Well, then this is just a collection of numbers separated by commas right and So from here what we would need to do is if I'm just ignoring everything else for a second There you go ignoring all of this stuff for just one second Just dealing with if I needed to represent the distance from Chicago to everywhere else in sort of my my list I've got each one of these integers and I would use square brackets to represent. Hey, we're dealing with a list so realistically what we're looking to do is just take this idea of using square brackets and having numbers inside those square brackets and What if I just took that and put it in its own list? And that's where we can start to think about this idea of making Additional collections and so as you can see going on here What we're dealing with is if I happen to have those distances I can start by having a sort of master list collection. So this is representing sort of my outer list and Then for every single entry that I just want in this big again collection of collections I can go in and add square brackets to represent that iteration I'm using air quotes here because it's not really because we're not dealing with loops But I could just represent them as each row of that table is its own Separate list and as you can see here I would add in additional curly braces to that now you might also notice at the very in here Not only do I happen to have the square bracket to represent the end of a list But again since we're dealing with sort of a list of lists a collection of collections I have a comma representing. Hey, I need to go to another location Now one thing that really starts to trip up students and I will fully apologize for this in advance to anyone watching this is trying to now navigate nested list Indices because now you're not just dealing with one right before When you were dealing with just one you just had one in the season So, you know, all I needed to do is say days at I don't know five And I knew exactly where that went it went to Friday Ta-da, but now that we're dealing with multiple lists We're starting to now think about how do I represent all of them? Well, the way to think about this for just a second is again, if we think about it this First portion of a variable or a list is just saying, you know again Go to this point in memory and then skip some set of numbers to get to In my particular case the fifth element in my list Now when we're dealing with you know, multi be multiple multiple Multi-dimensional lists, there's the word or nested list because that's easier to say What we're needing to do is specifically indicate Hey, which row am I on and then which column I'm on And we can do this by using more than one square bracket. So again, if we think about this I'm trying to find one where I haven't drawn on it yet Let's imagine that I happen to have this and I'll get rid of this for a second I happen to have my variable distances that is storing all of these values in a nested list now the first Indices that I would be looking to work off of is specifically my row and To represent that no different than when we're dealing with just the days of the week I would come in and just pick the number that I'm working off of so in my case Let's go with four. I want to look at row four Well, I would come in and just put in that four Now this is again where the headaches start to begin. How would I? Reference say for example, I want to look at this number right here 1549 so how would I get there? Well, I can see that yes It is in fact sort of the the two column, but how would I sort of code that out? Well in Python's Particular case the first thing you do is close out your bracket The way to think about this is what you're doing is you're effectively saying give me this remember This is just a list of numbers separated by commas So give me this list right here and So if we were to just print that out what we would get is That list of numbers of 1375 1763 Etc. Etc Now the way to continue thinking about this is what happens if I had just stored that as its own little variable Which I'm able to do that's perfectly legal in all our cases So what if I made x equal to distances at four? Okay? Well then remember it's just giving me back a list of numbers and so if I wanted to Access a particular value there. I could do x at two again That's just referencing the element in a list So without having to use a Additional variable what we can do is we can Utilize the fact that everything sort of to the left of our square brackets gets Evaluated first very similar to when we had nested function calls so all we would need to do in our case of getting our 1549 is distances for Close that square bracket to Now again what this is referring to is this idea Changed my color here this idea that I need to first evaluate. What is distances? Okay, well distances is again someplace in memory. I go and grab all of that information But then I say well I need to evaluate Distances at four and in this case again that is just going to instead of producing a string or a Numeric value like we did with just a normal list since we're dealing with nested lists. I just oh I get that this is a list and so finally finally Once I've gotten the location in memory and in particular the list the specific list in memory that I'm working for I can fully represent that using the two and we can see this so if I came in if I came in and Built that out and I've already cheated because it's a lot of typing of numbers So once again if I simply did distances at four distances at Four what I should see is the fourth element in my outer list So zero one two three four, so I should see again this fourth row and That's exactly what I see 1375 1763 1549 etc etc once again if I were to save this as a variable That didn't change anything so just to continue showing this That didn't change anything. I just said oh well make this list a variable and Then the same kind of way I can come in and treat this variable as if it is a list and print out that 1549 but finally again just to throw that concept out of the window We don't need to have a temporary X to Reference and get that that list. I could simply just say something like for Square bracket for square bracket 2 and it will once again get that same value So that's how we can work with nested lists