-1
def sumall(nm1, nm2) :
    return nm1 + nm2 

mynumber = [1, 5, 7, 9, 15, 130]
result = reduce(sumall, mynumber)

And this is the result in terminal

Traceback (most recent call last):
  File "g:\python\built_in_function6.py", line 25, in <module>
    new_func(sumall, mynumber)
  File "g:\python\built_in_function6.py", line 23, in new_func
    result = reduce(sumall, mynumber)
NameError: name 'reduce' is not defined
bereal
  • 32,519
  • 6
  • 58
  • 104

1 Answers1

0

You need to import the reduce function from the functools module.

from functools import reduce

And it will work.

enzo
  • 9,861
  • 3
  • 15
  • 38
NewHere
  • 61
  • 1
  • 8