# Dictionary

Dictionary is a collection of key-value pairs.

Key is a string, value is the data assigned to the key (like a dictionary).

Dictionary is very similar to arrays but it has keys instead of indexes.

<iframe
  loading="lazy"
  title="Python IDLE Trinket"
  src="https://trinket.io/embed/python3/f21c5175ba"
  height="400"
/>

## Declaring dictionary

Let's look at many examples.

1. The key can be either a numebr or a string.
2. The value can be any data type.

<iframe
  loading="lazy"
  title="Python IDLE Trinket"
  src="https://trinket.io/embed/python3/534b32664d"
  height="400"
/>

## `keys()`

This method is used to get all the keys in the dictionary.

It is uesful when you want to iterate over the keys.

It returns `dict_keys([keys])` data type and using `list()` method we can convert it to a list.

<iframe
  loading="lazy"
  title="Python IDLE Trinket"
  src="https://trinket.io/embed/python3/1e671b6947"
  height="400"
/>

## `values()`

This method is used to get all the values in the dictionary.

It is uesful when you want to iterate over the values.

It returns `dict_values([values])` data type and using `list()` method we can convert it to a list.

<iframe
  loading="lazy"
  title="Python IDLE Trinket"
  src="https://trinket.io/embed/python3/ef70d46c83"
  height="400"
/>
