The three functions below all concern a functional way to store a dictionary. We store a dictionary as a tuple of 2-tuples: index 0 of each 2-tuple is a key; index 1 is that key's associated value. The order of the keys is irrelevant, but keys are unique: no 2-tuples can have the same keys. For example the dictionary {'a': 1, 'b': 2, 'c': 3} might be stored as (('b',2), ('a',1), ('c', 3)) -or any other tuple with these 2-tuples in any order. We call such a data structure an association tuple. • Define a recursive function named get_assoc; it is passed an association tuple and key as arguments; it returns the value in the association tuple associated with the key. If the key is not in the association tuple, raise the KeyError exception. • Define a recursive function named del_assoc; it is passed an association tuple and key as arguments; it returns an association tuple that contains all associations except the one specified by the key parameter (keep the order of the other keys in the association tuple the same). If the key is not in the association tuple, raise the ReyError exception. Hint: build a new association tuple with all associations but the deleted one. • Define a recursive function named set_assoc; it is passed an association tuple, key, and associated value as arguments; it returns an association tuple that contains all associations with (a) a new 2-tuple added at the end for this association (if the key is nowhere in the association tuple) or (b) one of the associations changed (if the key is already in the tuple). Keep the key order the same. For example,

Solved
Show answers

Ask an AI advisor a question