[[02 - Notas de literatura/Linguagem de programação Python]] Dictionaries (DICT) are a set of ** key-value pairs **, where ** each key has a corresponding value **, as well as in a dictionary in the real world. In it each word (key) has a corresponding definition (value). In [[02 - Notas de literatura/Linguagem de programação Python]], we use keys to contain a dictionary and two points to denote keys and values. The dictionaries are indexed by their keys and not numerically.
For example:
`` `python
# Defines a Dictionary
Houses = {"Harry": "Gryffindor", "Draco": "Slytherin"}
# Prints the Value of the "Harry" Key
Print (Houses ["Harry"])
# Adds a New Element to the Dictionary.
Houses ["Hermione"] = "Gryffindor"
# Prints the Value of the "Hermino" Key
print (Houses ["Hermione"])
# Results In:
# Gryffindor
# Gryffindor
`` `
Some interesting methods about dictionaries are:
- `List (D)` - Returns a list of keys
- `Len (D)` - Returns the number of items in a list
- `D [Key]` - Indexes a key and generates a `keyerror` if the key does not demand
- `Iter (D)` - Returns an iterated to the dictionary keys
- `GET (Key, default)` - Returns the value of the key if it exists, otherwise returns default (standard `none`).
- `Popytem ()` - Removes and returns a key -value set (Last in First Out In Python 3.7+)
- `VALUES ()` - Returns a list of values.
:: ** Reference: ** :: [Python Documentation on Native Types] (https://docs.python.org/3/library/stdtypes.html)