Answers for "Write a Python Program to implement your own myreduce() function which works exactly like Python's built-in function reduce()"

1

Write a Python Program to implement your own myreduce() function which works exactly like Python's built-in function reduce()

def myreduce(anyfunc, sequence):

 # Get first item in sequence and assign to result
  result = sequence[0]
 # iterate over remaining items in sequence and apply reduction function 
  for item in sequence[1:]:
   result = anyfunc(result, item)

  return result
Posted by: Guest on September-15-2020

Code answers related to "Write a Python Program to implement your own myreduce() function which works exactly like Python's built-in function reduce()"

Python Answers by Framework

Browse Popular Code Answers by Language