5. Dictionaries¶
The dictionary itself consists of relating a key with a specific value
Unlike lists, where the index is a number, dictionaries use their keys as index
To add new elements that I don’t need to add, just make the session
If the key already exists: the associated value changes
If the key does not exist: the new key is added
Print output (drag lower right corner to resize)
|
Activity: CodeLens 5.1 (cl_l23_5a_en)
xxxxxxxxxx
d = {}
d["a"] = "alpha"
d["o"] = "omega"
d["g"] = "gamma"
print(d)
# This line will result in an error because there is no
# a "x" key in the dictionary
print(d["x"])
Activity: 5.2 ActiveCode (ac_l23_5_en)
Print output (drag lower right corner to resize)
|
Activity: CodeLens 5.3 (cl_l23_5b_en)
You have attempted 1 of 3 activities on this page