Python 3 Programming Tutorial - Multi-dimensional List
Key Takeaways
Creates a multi-dimensional list in Python 3
Full Transcript
What's going on everybody? Welcome to another Python 3 Basics tutorial video. In this video, what we're going to be talking about is multi-dimensional lists. So, all the lists that we've covered so far have been a singular dimension, right? So, there's just for each um bit of data in the list, it's only one bit of data. But actually, you can have lists within lists uh within lists within lists if you want. You can go as deep as you want. You can get very uh convoluted fast. Um, so anyway, what we're going to be showing today is a two-dimensional list and then you could take it from there if you so chose. So with that, let's go ahead and get started. So, uh, let's say we have a list and right now like a typical list, don't forget your square brackets. Let's just say we have, uh, the can't get away from these massive numbers. This is our list for now. Okay. Uh, and in fact, let's make that shorter, otherwise I'm going to cry. So, we have this list right now. So, we've got a five, a six, a six, and a two. So let's just make this a seven and two. Um so what we can do now this is a one-dimensional list but what we can do is we can make it a two-dimensional list. So each element in this list is just actually another list. So five and six and then we have a six and a seven and then a seven and a two and then a two and a five. Anybody see what I did there? Probably not. Anyway, continuing on. Um, so now we have a two-dimensional list. So for one, we can just print x. Save and run that. Apparently it's this is uh really challenging. There we go. Okay. So here's our list. Now uh let's say we want to print the first element here. It's a six and a seven. Now what if we wanted to go even deeper? Well, we can go deeper uh using the same sort of syntax. So we can say we want the first element or the zeroith element which will be hopefully a six. Right? We have 67. The first of that is a six. Save and run it and we get a six. So that's how we can reference that. Now we could go even further, right? So this is a two-dimensional list. We could take this even further and say like these numbers here, this could be a list as well. And then we could have another list here. Um, then another list. Let me make sure I've done this right. This gets messy very fast, which is what I'm about to talk about here. Um, 66 and then 78. Um, we'll leave it like that for now. We don't actually have to go further. Let me make sure that's a valid list. Okay. So, um, so this printed now you can see this is, you know, two elements. So, let's say, you know, you want to go even further. Well, obviously we still can go further. So the zeroth of the zeroith again a six. Now as you can see you just typing this out was a kind of a pain. Also just visually looking at it it's kind of a pain to look at this. Uh so what you can do when you make big lists like this is um see like with Python we don't have to have very nice standards necessarily all the time. It kind of Python like forces us into having standards. So as a programmer you maybe forget the fact that you might need to program your own standards. Again, what I mean by standards is the organization of all the text here. So, but what you can do with lists, tupils, um, well, really a whole bunch of stuff, but mostly you're going to do it with lists is you can do the following. You can hit enter. And now this is the, you know, I'm pointing to the screen. You can't see that. Uh, so like this is our our opening bracket. And then we might as well put our closing bracket right down there as well. And then this is our second bracket here. And if you ever want to know um you know what each bracket corresponds to uh you can kind of you can do this. Oops. You can delete it and add it and you can see how it highlights everything. That's kind of how you know like what that bracket corresponds to. So if you're used to like like say you code in like Notepad++ sometimes it does it automatically for you if you like highlight the little bracket especially like curly braces. Say you're programming I don't know PHP or something you highlight them and it kind of corresponds. So if you ever want to know like what bracket that is or if you've actually closed everything you could just do that. Um so anyway then we can see you know these are their own little pair and then this is a group here and then you can either put the commas at the bottom or I like to leave them at the end like this. Um I'm pointing at the screen again you can't see like this at the end here because uh you can go like this and then everything is nice and organized and then do it one more time. This didn't have any lists within a list, so it's not as all pretty and organized, but you get the idea. Um, so we can still run this though, and Python, you know, still deals with it and handles it just like you would hope. Um, and then here, let me show you that. We'll run it. Same thing. So, you can add spaces and it's okay. So, if you, you know, if you're kind of OCD about making everything look pretty, um, you can get away with it. So, anyway, uh, that's just some an example of multi-dimensional lists. Again, you can go as deep into this as you want and it just helps to organize. God, just keep pointing at this screen. I need to like a camera behind me so you guys can see what I'm pointing at. Um, you can organize it like this. And obviously, as you get more and more dimensions, it's going to get almost impossible, right? Because your screen is, you know, still only two dimensions. So, as soon as you get past a two-dimensional list, you're kind of screwed again. But anyway, uh, it does help to kind of organize it a little bit. So, that's going to conclude uh this video. If you guys have any questions or comments, please feel free to leave them below. As always, thanks for watching. Thanks for all the support and subscriptions.
Original Description
In this Python 3 programming tutorial, we cover the multi-dimensional list. Up until now, we have focused on single dimensional lists, but this is limiting. In programming, we are able to create lists with infinite depth. Here's how!
Sample code for this basics series: http://pythonprogramming.net/beginner-python-programming-tutorials/
Python 3 Programming tutorial Playlist: http://www.youtube.com/watch?v=oVp1vrfL_w4&feature=share&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M
http://seaofbtc.com
http://sentdex.com
http://hkinsley.com
https://twitter.com/sentdex
Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
🎓
Tutor Explanation
DeepCamp AI