<jupyter_start><jupyter_text>Dictionary: Ordered Associative ArrayDictionaries are also known as hashtables. The keys of a dictionary must be hashable. The values may be any type of object (including lambda, list, string or even another dictionary).[Python Dictionaries | python.org](https://docs.python.org/3.8/library/stdtypes.html?highlight=dict%20typemapping-types-dict)<jupyter_code>my_dictionary = {
    "alpha": 1,
    "beta": 2,
    "gamma": 3,
    "zeta": 42,
}

print(my_dictionary)<jupyter_output>{'alpha': 1, 'beta': 2, 'gamma': 3, 'zeta': 42}<jupyter_text>Reading an item:While the first example below is a bit more Pythonic, the second one is far more common. The `.get()` method will return `None` if the key does not exit in the dictionary. The second example will raise a KeyError instead.<jupyter_code>a = my_dictionary.get("alpha")
print("a is", a)<jupyter_output>a is 1<jupyter_text>or...<jupyter_code>b = my_dictionary["beta"]
print("b is", b)<jupyter_output>b is 2<jupyter_text>Adding an item:<jupyter_code>my_dictionary["delta"] = 4
print(my_dictionary)<jupyter_output>{'alpha': 1, 'beta': 2, 'gamma': 3, 'zeta': 42, 'delta': 4}<jupyter_text>Removing an item:<jupyter_code>z = my_dictionary.pop("zeta")

print("z is", z)
print(my_dictionary)<jupyter_output>z is 42
{'alpha': 1, 'beta': 2, 'gamma': 3, 'delta': 4}<jupyter_text>Printing the Keys and Values:<jupyter_code>dict_keys = my_dictionary.keys()
dict_vals = my_dictionary.values()

print(dict_keys)
print(dict_vals)<jupyter_output>dict_keys(['alpha', 'beta', 'gamma', 'delta'])
dict_values([1, 2, 3, 4])<jupyter_text>Dictionary IterationThe following is only possible because dictionaries are now ordered - since Python 3.6. They maintain the order you give them, if you add an item, it is added to the end of the dictionary. In previous versions of Python, dictionaries were not ordered, in fact - they were randomized. Printing Keys Only<jupyter_code>for key in my_dictionary.keys():
    print(key)<jupyter_output>alpha
beta
gamma
delta<jupyter_text>Printing Values Only<jupyter_code>for value in my_dictionary.values():
    print(value)<jupyter_output>1
2
3
4<jupyter_text>Printing Keys and Values with Formatting<jupyter_code>for key, val in my_dictionary.items():
    print(f"{key}: {val}")<jupyter_output>alpha: 1
beta: 2
gamma: 3
delta: 4<jupyter_text>Dictionary Comprehension<jupyter_code>char = ('a', 'b', 'c', 'd', 'e', 'f')
nums = ( 0,   1,   2,   3,   4,   5 )

dict_comp = {k: v for k, v in zip(char, nums)}

print(dict_comp)<jupyter_output>{'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5}
{'fraction_non_alphanumeric': 0.14064316156528478, 'fraction_numerical': 0.021309569934134055, 'mean_word_length': 6.073972602739726, 'pattern_counts': {'":': 4, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '459699', 'license': 'MIT', 'n_tokens_mistral': 1004, 'n_tokens_neox': 919, 'n_words': 270, 'path': 'WEEKS/CD_Sata-Structures/_RESOURCES/python-prac/Intro_to_Python/06_associative_array.ipynb', 'repo_name': 'webdevhub42/Lambda', 'size': '2581'}