Multi-dimensional lists Python Tutorial



In this Python 3 tutorial, we cover the concept of multi-dimensional lists. Multi dimensional lists are lists within lists, or lists within lists within lists... you get the point. It can get very confusing very fast, but it is good to know that it is an option. Usually a dictionary will be the better choice rather than a multi-dimensional list in Python, but, if you are familiar with multi-dimensional arrays in other languages, you might want to continue that concept in Python.

Lists that we have covered so far have all been 1 dimensional, but you can have lists within lists within lists within lists if you want.

We already know how to reference elements in a list, we can do:

x = [[2,6],[6,2],[8,2],[5,12]]
print(x[2])

We can also take this deeper since we have more dimensions now:

print(x[2][1])

This can go on indefinitely with very thick lists. You might see how this can quickly get messy, so let's consider how to properly display lists in code that have many dimensions. You might not typically hard code multi-dimensional lists, but there are some instances where you will.

y = [[5,2],
     [6,2],
     [3,1],
     [12,6]
    ]

This is slightly cleaner, and python automatically understands it:

print(y)

There exists 1 quiz/question(s) for this tutorial. for access to these, video downloads, and no ads.

The next tutorial:





  • Python Introduction
  • Print Function and Strings
  • Math with Python
  • Variables Python Tutorial
  • While Loop Python Tutorial
  • For Loop Python Tutorial
  • If Statement Python Tutorial
  • If Else Python Tutorial
  • If Elif Else Python Tutorial
  • Functions Python Tutorial
  • Function Parameters Python Tutorial
  • Function Parameter Defaults Python Tutorial
  • Global and Local Variables Python Tutorial
  • Installing Modules Python Tutorial
  • How to download and install Python Packages and Modules with Pip
  • Common Errors Python Tutorial
  • Writing to a File Python Tutorial
  • Appending Files Python Tutorial
  • Reading from Files Python Tutorial
  • Classes Python Tutorial
  • Frequently asked Questions Python Tutorial
  • Getting User Input Python Tutorial
  • Statistics Module Python Tutorial
  • Module import Syntax Python Tutorial
  • Making your own Modules Python Tutorial
  • Python Lists vs Tuples
  • List Manipulation Python Tutorial
  • Multi-dimensional lists Python Tutorial
  • Reading CSV files in Python
  • Try and Except Error handling Python Tutorial
  • Multi-Line printing Python Tutorial
  • Python dictionaries
  • Built in functions Python Tutorial
  • OS Module Python Tutorial
  • SYS module Python Tutorial
  • Python urllib tutorial for Accessing the Internet
  • Regular Expressions with re Python Tutorial
  • How to Parse a Website with regex and urllib Python Tutorial
  • Tkinter intro
  • Tkinter buttons
  • Tkinter event handling
  • Tkinter menu bar
  • Tkinter images, text, and conclusion
  • Threading module
  • CX_Freeze Python Tutorial
  • The Subprocess Module Python Tutorial
  • Matplotlib Crash Course Python Tutorial
  • Python ftplib Tutorial
  • Sockets with Python Intro
  • Simple Port Scanner with Sockets
  • Threaded Port Scanner
  • Binding and Listening with Sockets
  • Client Server System with Sockets
  • Python 2to3 for Converting Python 2 scripts to Python 3
  • Python Pickle Module for saving Objects by serialization
  • Eval Module with Python Tutorial
  • Exec with Python Tutorial