The Python Oracle

NameError: name 'reduce' is not defined in Python

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Puzzle4

--

Chapters
00:00 Nameerror: Name 'Reduce' Is Not Defined In Python
00:33 Accepted Answer Score 347
00:41 Answer 2 Score 277
00:51 Answer 3 Score 10
01:00 Answer 4 Score 4
01:12 Thank you

--

Full question
https://stackoverflow.com/questions/8689...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #reduce #python32

#avk47



ACCEPTED ANSWER

Score 347


It was moved to functools.




ANSWER 2

Score 277


You can add

from functools import reduce

before you use the reduce.




ANSWER 3

Score 10


Or if you use the six library

from six.moves import reduce



ANSWER 4

Score 4


Reduce function is not defined in the Python built-in function. So first, you should import the reduce function

from functools import reduce