Test your knowledge with free interactive questions on Seneca — used by over 10 million students.

Lists

Lists are a data structure quite similar to an array.

Lists

Lists

  • Lists store multiple elements of different data types under the same identifier.
  • There can be a variable number of elements - they never get full.
Lists in pseudocode

Lists in pseudocode

  • A list can be declared as follows:
    • pupils = []
  • Values can be added to the end of the list as follows:
    • pupils.append("Alice")
  • Values can be accessed as follows:
    • print("The first student is " + pupils[0])

2D Lists

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

2D List

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.
Accessing elements

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]).
Uses of 2D lists

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
1

Introduction to Python

2

Data Structures

2.1

Lists & Strings

2.2

File Handling

3

Modularity

3.1

Subroutines

3.2

Data Flow

4

Good Practice

4.1

Naming & Whitespace

4.2

Comments

4.3

Exceptions

Practice questions on Lists

Can you answer these? Test yourself with free interactive practice on Seneca — used by over 10 million students.

  1. 1
  2. 2
    How is a list created?Multiple choice
  3. 3
  4. 4
Answer all questions on Lists

Unlock your full potential with Seneca Premium

  • Unlimited access to 10,000+ open-ended exam questions

  • Mini-mock exams based on your study history

  • Unlock 800+ premium courses & e-books

Get started with Seneca Premium