2.1.17

2D Lists

Test yourself

2D Lists

A 2D list is the data structure which consists of a list of lists.

Illustrative background for 2D ListIllustrative background for 2D List ?? "content

2D List

  • A 2D list is a data structure where lists are filled with other lists.
  • This can be used to represent a 2D surface, or records.
Illustrative background for Accessing elementsIllustrative background for Accessing elements ?? "content

Accessing elements

  • To access an individual list we can access the list as usual:
    • list = my2DList[4]
  • To access an individual element, we use this syntax:
    • list[5][0]
  • This would get the first element ([0]), of the sixth list ([5]).
Illustrative background for Uses of 2D listsIllustrative background for Uses of 2D lists ?? "content

Uses of 2D lists

  • 2D lists are often used to represent a 2D surface, for example a chess board:
    • Each element of the 2D list could contain the chess piece in that location.
  • 2D lists can be used to represent a database:
    • Each inner list can store a record of the database.
    • The outer list can store each record.

Jump to other topics

1Computational Thinking & Algorithms

2Programming

3Hardware & Software

4Data

5The Internet

6Online Safety & Security

Go student ad image

Unlock your full potential with GoStudent tutoring

  • Affordable 1:1 tutoring from the comfort of your home

  • Tutors are matched to your specific learning needs

  • 30+ school subjects covered

Book a free trial lesson