# Lists & Dictionaries

### Why does python make a reference to a list and not create a new variable?

But why does Python have this whole complicated reference system to begin with.

And will you have to consider list can be huge in our code right here.

It just has three integers that's only a few bytes of your computer's memory.

But say that this was I don't know 4 billion integers instead of just you know these three right here

Then it would be a huge problem to copy that entire list would all four billion values every time you

make a function call right here.

So as a default sort of shortcut it just stores this list once and instead just assigns a really cheap

and easy to handle list of reference to this variable.

And on that list reference gets copied because it's just a few bites and memory it just points to this

### List continuation

You don't have to follow indentation when you are inside a list:&#x20;

![](https://846345873-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LagOeJ2nL90MQERwhxy%2F-LhDCdx6ZyQzpJ6b6V_5%2F-LhDqfOo-ZKek9k01BA-%2Fimage.png?alt=media\&token=445ba6e1-3c9d-4da9-83a1-0d8da2d421ac)

It's the same for \\&#x20;

### List Recap

![](https://846345873-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LagOeJ2nL90MQERwhxy%2F-LhDCdx6ZyQzpJ6b6V_5%2F-LhDr0fbPb9tb2zICYHW%2Fimage.png?alt=media\&token=808b94e1-29f6-4768-9a1c-1d3a410343d5)

### Dictionaries

![](https://846345873-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LagOeJ2nL90MQERwhxy%2F-LhcY84H3sxlmO2dDK82%2F-LhcZ1DwW6GMN4O9Kbf5%2Fimage.png?alt=media\&token=b76b5fe8-e47c-4517-aa72-f59210ea0f5e)

Dictionaries don't have order.&#x20;

**Get**

![](https://846345873-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LagOeJ2nL90MQERwhxy%2F-LhcY84H3sxlmO2dDK82%2F-Lhca9JT6zDIlJFIcZXP%2Fimage.png?alt=media\&token=989bceb6-af18-4847-b102-e3976104bd43)

**setdefault**

![](https://846345873-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LagOeJ2nL90MQERwhxy%2F-LhcY84H3sxlmO2dDK82%2F-LhcahzEgGDz8KKksThB%2Fimage.png?alt=media\&token=6de1a310-5f9f-4688-911e-5cc608b437dd)

Example of setdefault

```python
import pprint

message = 'It was a bright cold day in APril, and the clocks were stricking.'
count = {}

for character in message.upper():
    count.setdefault(character, 0)
    count[character] = count[character] + 1

pprint.pprint(count)
```

Output:

{'I': 6, 'T': 4, ' ': 12, 'W': 2, 'A': 5, 'S': 3, 'B': 1, 'R': 4, 'G': 2, 'H': 2, 'C': 4, 'O': 2, 'L': 3, 'D': 3, 'Y': 1, 'N': 3, 'P': 1, ',': 1, 'E': 3, 'K': 2, '.': 1}

![](https://846345873-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LagOeJ2nL90MQERwhxy%2F-LhcY84H3sxlmO2dDK82%2F-LhccwZjdw_PzQqcn4PW%2Fimage.png?alt=media\&token=6eae7be8-514b-48cd-9010-414a2e43e45e)
