Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We use a \"dictionary of sets\" to store equivalences for the problems below: ea

ID: 3802148 • Letter: W

Question

We use a "dictionary of sets" to store equivalences for the problems below: each value is associated with a set of all the values it is equivalent to. For example, let us define an equivalence of birthdays. If people named 'a', 'b', and 'c' had equivalent birthdays (born on the same day, regardless of the year), and people named 'd', and 'e' had equivalent birthdays, and no one else had the same birthday as 'f', then we could represent this information in the following equivalence dictionary: in it each person's name is a key, and each key is associated with the set of names of people who have the same birthday (are equivalent). ed = {'a': {'a', 'b', 'c'}, 'b': {'a', 'b', 'c'}, 'c': {'a', 'b', 'c'}, 'd': {'d', 'e'}, 'e': {'d', 'e'}, 'f': {'f'}} Define a function equiv that takes three arguments: an equivalence dictionary and two strings (names): it returns True whenever the two names are equivalent, otherwise False: equiv (ed, 'a', 'b') returns True

Explanation / Answer

We can make a code like this in python:

eq={'a':{'a','b','c'}, 'b':{'a','b','c'}, 'c':{'a','b','c'}, 'd':{'d','e'}, 'e':{'d','e'},'f':{'f'}}

def equiv(ed,p1,p2):
if(ed[p1]==ed[p2]):
return True
return False

#lets test the function
print(equiv(eq,'a','b')) #this will print true

print(equiv(eq,'a','f')) #this will print false

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote