When I try this code in Python 3.x, I get an error message that says "NameError: global name ‘reduce’ is not defined".
def main():
def add(x,y): return x+y
reduce(add, range(1, 11))
if __name__=='__main__':
main()
Why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m going to guess that:
The
reducefunction, since it is not commonly used, was removed from the built-in functions in Python 3. It is still available in thefunctoolsmodule, so you can do: