Question: PYTHON 3 language please Define the multidict_lookup function , which has any number of arguments that are dicts. This function returns a function object that
PYTHON 3 language please
Define the multidict_lookup function, which has any number of arguments that are dicts. This function returns a function object that has one argument call it name. When the returned function object is called, it returns the value associated with name in the first dict in which it appears. If it does not appear as a key in any dict, the function raises the NameError exception. For the example scope = multidict_lookup ({'a':1}, {'b':2}, {'a':3}), then calling scope(a) returns 1; calling scope(b) returns 2; callingscope(c) raises NameError. For the last point, determine how scopes function object can store an attribute named successes that remembers the number of times calling scope successfully returned a result; after doing the previous three calls to scope, then scope.successes evaluates to 2. Hint: function objects can store attributes, but the code to do so will look strange. example: scope1 = multidict_lookup ({'a':1}, {'b':2}, {'a':3}) scope2 = multidict_lookup (dict(a=1,x=10), dict(b=2,y=11,z=12), {'a':3, 15:'z'}) [scope2('a'),scope2('b'),scope2('x'),scope2('y'),scope2('z'),scope2(15)] (output = [1, 2, 10, 11, 12, 'z']) scope1.successes (output = 0) [scope1('a'),scope1('b')] scope1.successes (output = 2) scope2.successes (output = 6)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
