`[]`

¶*A review*

In [2]:

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

Out[2]:

'plums'

In [3]:

```
fruits[1]
```

Out[3]:

'peaches'

In [4]:

```
fruits[3]
```

Out[4]:

'persimmons'

In [5]:

```
fruits[4]
```

In [6]:

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

Out[6]:

'persimmons'

In [7]:

```
fruits[-3]
```

Out[7]:

'peaches'

In [8]:

```
fruits[-4]
```

Out[8]:

'plums'

In [9]:

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

Out[9]:

('persimmons', 'persimmons')

`range`

¶In [23]:

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

0 1 2 3 4

In [10]:

```
range(5)
```

Out[10]:

range(0, 5)

In [24]:

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

Out[24]:

[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 [27]:

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

Out[27]:

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

In [43]:

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

Out[43]:

[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 [44]:

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

Out[44]:

[1, 2, 3, 4, 5]

In [45]:

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

Out[45]:

[0, 2, 4, 6, 8]

In [15]:

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

Out[15]:

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

In [16]:

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

Out[16]:

[5, 4, 3, 2]

In [48]:

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

Out[48]:

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

In [49]:

```
bears[3]
```

Out[49]:

'koala'

In [50]:

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

In [51]:

```
bears[3]
```

Out[51]:

'panda'

In [52]:

```
bears
```

Out[52]:

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

How do these functions compare?

In [23]:

```
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 [24]:

```
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 [26]:

```
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