Question: Python 5. (4 pts) We learned that when we declare a class using inheritance, the_bases_attribute of the class is bound to a tuple of references

Python 5. (4 pts) We learned that when we declare a classPython

5. (4 pts) We learned that when we declare a class using inheritance, the_bases_attribute of the class is bound to a tuple of references to its base classes. Write a recursive function named bases that takes a reference to any class and returns a set containing that class and all its base classes (all the way back to the object class). You may not use the _mro_ or mro attributes of the class, which would trivialize your function. You may use both iteration (over the _bases__ list) and recursion to write this function. For example, given the following class definitions in a script (class A appears as_main_.A) class F:pass class C:pass class G:pass class B(F) :pass class D(G) :pass class A(B,C,D) :pass Calling bases (A) returns the set [, , , } main--.G">, , , ' Hint: the union method for a set takes any number of arguments (other sets: a.union (b,c,d)) and computes the union of all of them Remember how to use * to take a tuple of sets and convert them into that many set arguments in a function call.. You can also use functools.reduce with | (the set union operator: a | b)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!