Source: https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/2-1-1-lists

[Revision notes](https://senecalearning.com/en-gb/revision-notes.md) › [GCSE](https://senecalearning.com/en-gb/revision-notes/gcse.md) › [Coding](https://senecalearning.com/en-gb/revision-notes/gcse/coding.md) › [National Curriculum](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum.md) › Lists

# Lists

Coding: Introduction to Python v3, topic 2.1.1

## Lists

Lists are a data structure quite similar to an array.

### Lists

![Lists](https://image-v2.cdn.app.senecalearning.com/2018-09/3fba2487-0107-4ee7-9e33-50edfe5b6f04/checklist-ticklist-tick-list-.jpg)

- 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](https://image-v2.cdn.app.senecalearning.com/2018-09/3d7d187f-ce76-4b7e-8fa7-8aabc6b43a25/to-do-list.jpeg)

- 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](https://image-v2.cdn.app.senecalearning.com/courseImages/chemistry/1.1.3%20-%20Periodic%20table/1000px-Periodic_table_by_Mendeleev,_1871.svg-min.jpg)

- 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](https://image-v2.cdn.app.senecalearning.com/2018-09/f030eba3-b68d-4b3c-a597-26e9d34b9eef/today-list.jpeg)

- 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](https://image-v2.cdn.app.senecalearning.com/2018-09/a318dc7e-cd70-42c7-a544-f41b36c8ef18/coup.jpg)

- 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 represents a single record (row) in the database.
 - The outer list contains all the records, representing the entire table.

## Test yourself on Lists

- Which of these are true of lists?
- How is a list created?
- What would the command list[5].append(3) do to a 2D list?

[Practise this topic for free](https://app.senecalearning.com/classroom/course/72d0364c-db0a-4630-8e0a-61f48cae0252/section/cd3ee260-5db3-4b22-bcdf-48cc6c7236f4/session)

- Previous topic: [1.6.2 Iteration](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-6-2-iteration.md)
- Next topic: [2.1.2 Strings](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/2-1-2-strings.md)

## Coding: Introduction to Python v3 contents

### 1 Introduction to Python
- 1.1 Python
  - [1.1.1 Python](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-1-1-python.md)
- 1.2 Input & Output
  - [1.2.1 Input & Output](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-2-1-input-and-output.md)
- 1.3 Data Types
  - [1.3.1 Data Types](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-3-1-data-types.md)
- 1.4 Variables & Constants
  - [1.4.1 Variables & Constants](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-4-1-variables-and-constants.md)
- 1.5 Operators
  - [1.5.1 Arithmetic & Relational Operators](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-5-1-arithmetic-and-relational-operators.md)
  - [1.5.2 Boolean & Assignment Operators 2](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-5-2-boolean-and-assignment-operators-2.md)
- 1.6 Program Flow
  - [1.6.1 Selection](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-6-1-selection.md)
  - [1.6.2 Iteration](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/1-6-2-iteration.md)

### 2 Data Structures
- 2.1 Lists & Strings
  - [2.1.1 Lists](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/2-1-1-lists.md)
  - [2.1.2 Strings](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/2-1-2-strings.md)
- 2.2 File Handling
  - [2.2.1 File Handling](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/2-2-1-file-handling.md)

### 3 Modularity
- 3.1 Subroutines
  - [3.1.1 Subroutines](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/3-1-1-subroutines.md)
- 3.2 Data Flow
  - [3.2.1 Data Flow](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/3-2-1-data-flow.md)

### 4 Good Practice
- 4.1 Naming & Whitespace
  - [4.1.1 Identifiers](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-1-1-identifiers.md)
  - [4.1.2 Whitespace](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-1-2-whitespace.md)
- 4.2 Comments
  - [4.2.1 Comments](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-2-1-comments.md)
- 4.3 Exceptions
  - [4.3.1 Exceptions](https://senecalearning.com/en-gb/revision-notes/gcse/coding/national-curriculum/4-3-1-exceptions.md)
