`[]`

¶*A review*

In [1]:

```
fruits = ['plums', 'peaches', 'pears', 'persimmons']
fruits[0]
```

Out[1]:

'plums'

In [2]:

```
fruits[1]
```

Out[2]:

'peaches'

In [3]:

```
fruits[3]
```

Out[3]:

'persimmons'

In [4]:

```
fruits[4]
```

In [5]:

```
fruits = ['plums', 'peaches', 'pears', 'persimmons']
fruits[-1]
```

Out[5]:

'persimmons'

In [6]:

```
fruits[-3]
```

Out[6]:

'peaches'

In [7]:

```
fruits[-4]
```

Out[7]:

'plums'

In [8]:

```
fruits[len(fruits)-1], fruits[-1]
```

Out[8]:

('persimmons', 'persimmons')

`range`

¶In [9]:

```
for i in range(5):
print(i)
```

0 1 2 3 4

In [10]:

```
range(5)
```

Out[10]:

range(0, 5)

In [11]:

```
list(range(5))
```

Out[11]:

[0, 1, 2, 3, 4]

In [12]:

```
fruits = ['apples', 'apricots', 'avacados']
for index in range(len(fruits)):
print(fruits[index])
print()
# Same as
for fruit in fruits:
print(fruit)
```

apples apricots avacados apples apricots avacados

In [13]:

```
list(range(4, 12))
```

Out[13]:

[4, 5, 6, 7, 8, 9, 10, 11]

In [14]:

```
list(range(4, 12, 2))
```

Out[14]:

[4, 6, 8, 10]

What python expression using `range`

would you use to create the following sequences?

`1, 2, 3, 4, 5`

`0, 2, 4, 6, 8`

`-6, -3, 0, 3, 6`

`5, 4, 3, 2`

In [15]:

```
list(range(1, 6))
```

Out[15]:

[1, 2, 3, 4, 5]

In [20]:

```
list(range(0, 9, 2))
```

Out[20]:

[0, 2, 4, 6, 8]

In [17]:

```
list(range(-6, 9, 3))
```

Out[17]:

[-6, -3, 0, 3, 6]

In [19]:

```
list(range(1.1, 6.6, 1.1))
```

In [18]:

```
list(range(5, 1, -1))
```

Out[18]:

[5, 4, 3, 2]

In [21]:

```
bears = ['brown','black','polar','koala']
bears
```

Out[21]:

['brown', 'black', 'polar', 'koala']

In [22]:

```
bears[3]
```

Out[22]:

'koala'

In [27]:

```
bears[3] = 'panda'
```

In [24]:

```
bears[3]
```

Out[24]:

'panda'

In [25]:

```
bears
```

Out[25]:

['brown', 'black', 'polar', 'panda']

How do these functions compare?

In [28]:

```
def large_value_of_two(items):
"""Replace 2 with something bigger (like 5)"""
new_items = []
for item in items:
if item == 2:
item = 5
new_items.append(item)
return new_items
```

In [29]:

```
def large_value_of_2(items):
"""Replace 2 with something bigger (like 5)"""
for i in range(len(items)):
if items[i] == 2:
items[i] = 5
```

In [30]:

```
numbers = [1, 2, 3, 4]
print("Numbers before:", numbers)
first_return = large_value_of_two(numbers)
print("Numbers after:", numbers)
print("large_value_of_two returned:", first_return)
print()
print("Numbers before:", numbers)
second_return = large_value_of_2(numbers)
print("Numbers after:", numbers)
print("large_value_of_2 returned:", second_return)
```

Just because a function **can** change a list doesn't mean it **should**.

**immutability** whenever possible: only change inputs when there is a clear advantage over making a copy

Clearly define and document the intent of your functions.

- does a function
**change**the input or only**read**the input?

`edits.py`

¶`score_board.py`

¶- indexing lists with
`[]`

`range`

- list mutability