Question: There are two functions here. One is an implementation of reduce. I want to know how I can go about writing a second function func,
There are two functions here. One is an implementation of reduce. I want to know how I can go about writing a second function func, that takes in a list and a key, then searches the list for the key using the already defined reduce function in python. thank you.
def func(list_, key)
#code
def reduce(f, id_, a):
print(a)
if len(a) == 0:
return id_
elif len(a) == 1:
return a[0]
else:
res = f(reduce(f, id_, a[:len(a)//2]), reduce(f, id_, a[len(a)//2:]))
return res

def func(list_, key): #code pass def reducelf, val, a): #a is the list # val is the key Value if len(a) == 0: | return val elif len(a) == 1: return a[0] else: res = f(reduce(f, val, a[:len(a)//2]), reduce(f, val, allen(a)//2:])) if res ==val: print(val)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
