Multi-Dimensional Lists

Setting up a multi-dimensional list

Lists can be given another dimension to hold data that is related to each other.

A scenario: Three students have taken two Chemistry tests and their teacher has recorded the results in a 2 dimensional array (note that Python does not use arrays but uses lists instead):


To add this to Python we would write:


Printing a multi-dimensional list

To print each record in the list (I have altered the generic ‘i’ count variable to be more descriptive):


This would output:


Printing a specific record

To print a record from its index number (look at the table above and remember that Python starts counting at 0: so Edward is record 0, Bella 1 and Jacob 2):


This would output:


Printing a specific data value

To print a specific data value then you need to define the record number and then the data index. Use the table above to help you visualise this:


Edward is the zero record and the first value is his 34 score:  lists28

Searching for a specific value

To search through a multi-dimensional list then you need to search through each record and then each data element for a specific value:


This would output:


< Back to Section Eight