get it on google playCreated with Sketch.
Python> Dictionaries

Dictionaries

Dictionaries are kind of like lists and tuples but, instead of using index numbers, they use keys to point to values.

numbers = {"one": "un",
  "two": "deux"}
print(numbers)

Unlike the index numbers of lists and tuples, keys can be of any type.

numbers = {"one": "un",
  "two": "deux"}
numbers[3] = "trois"
numbers[True] = "quatre"
print(numbers)

What if we want to get a list of keys, though? Well, there's a method that returns a dictionary's keys instead of its values.

n = {"one": "un", "two": "deux"}
print(n.keys())

While dictionaries don't have an order like lists and tuples, we can ask for their lengths in the usual way.

n = {"one": "un", "two": "deux"}
print(len(n))

In order to add or change values to a dictionary, we can also use the update() method with the key-value pairs we want to add in braces.

n = {"one": "un", "two": "deux"
n.update({"three": "trois"})
print(n)
TRY IT ON THE APP