**Definition:** A list is a *ordered* sequence of possibly *inhomogeneous* elements. Python lists are the programmatic embodiement of the mathematical notion of $n$-tuple:

where the $i^{th}$ element belongs to the set $A_i$ (the sets being $A_i$s potentially disticts).

In Python, one can use the same notation as in math, in which case the list elements won't be able to be modified after having been assigned. In the Python lingo, these constant lists are also called *tuples*.

```
In [ ]:
```

*mutable* list (i.e. a list whose elements can be further modified), Python uses *square brackets* instead of parenthesis:

```
In [ ]:
```

*subscript* notation $a_i$ to denote the $i^{th}$ element of a list $a$. Instead of that notation, Python uses the *square bracket operator* (caution: in Python indices start at zero):

```
In [ ]:
```

```
In [ ]:
```

*mutable* and Python tuples are called *immutable*:

```
In [ ]:
```

```
In [ ]:
```

```
In [ ]:
```

Algorithmically, one may be interseted in lists for various reasons:

looping over elements (as we have already seen)

retrieving

*sublists*of a given listssorting the list elements according to a particular criterium

**Sublists**

One retrieves from a given Python's list, say `my_list`

, a sublist of consecutive indices by indicating the **sublist range or "slice":**

`my_list[3:6]`

returns the sublist
`[my_list[3], my_list[4], my_list[5]]`

```
In [ ]:
```

The function `len(my_list)`

returns the **length** of my_list

```
In [ ]:
```

- The range $[m:n]$ is
**open-ended**: element $m$ is included but not the element $n$ - $[:n]$ is a shorthand for $[0:n]$
- $[m:]$ is a shorthand for $[m:n]$ where $n$ is the list lenght
- Negative numbers can also be used to indicate positions and ranges:
`my_list[-1]`

is the last element of the list`my_list[-2]`

is the element before the last element, etc.- etc.

**Sorting**

```
In [ ]:
```

```
In [ ]:
```