-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
  • 29,394
  • 6
  • 53
  • 86

1 Answers1

0

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

from functools import reduce

And it will work.

enzo
  • 9,121
  • 2
  • 12
  • 36
NewHere
  • 61
  • 7