# Dictionary

### Dictionary:

mutable, dictionary can be modified.

Dictionary is a collection of key value pairs, for example: {‘a’:1,’b’:2,’c’:3}

Dictionary keys and values are sequences, iterables

```
d={'a':1,'b':2,'c':3}
for i in d.keys():
    print(i)
    
a
b
c

d={'a':1,'b':2,'c':3}
for i in d.values():
    print(i)
    
1
2
3
```

d\[‘a’] is 1, d\[‘b’] is 2, d\[‘c’] is 3

You can also create a dictionary that way, use function dict()

d=dict(a=1,b=2,c=3)

Above is the same as

d={‘a’:1,’b’:2,’c’:3}

d\['a'] is 1

Dictionary is an object, meaning it has methods and attributes that can be invoked

To see all methods, type

help(\<dictionary variable>)

In Jupyter notebook, to see list of methods or attributes

Press shift key after enter \<Dictionary variable>.

![](https://2100080250-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M1PNTHVApkPePuMdTu3%2F-M1fbJhj77XTmXMxbhaJ%2F-M1fcnDfwunfyBggcgLH%2Fpython_dict.jpg?alt=media\&token=736bd3ce-3645-4cad-bb18-41606ea8c422)

