Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Functional Python The Lambda Lambada Reduce

expected reduce to return the final returned product (single value) but got the recursive representation of computation

Not sure if I m missing something here.. I expected reduce() to return the final returned product (single value) but got the recursive representation of computation instead as seen in the output below..

#understanding reduce
import functools

def prod(x,y):
    return x,y

ls = list(range(1,11))  #[i for i in range(1,11)]
print(functools.reduce(prod,ls))

print(functools.reduce(prod,[1,2,3,4,5,6,7,8,9,10]))

output:

(((((((((1, 2), 3), 4), 5), 6), 7), 8), 9), 10) (((((((((1, 2), 3), 4), 5), 6), 7), 8), 9), 10)

2 Answers

Please format your code properly. Read the Markdown Cheatsheet below the answer box :arrow_heading_down:

done!

Ross Coe
Ross Coe
5,061 Points

prod x*y no?! you're currently returning a (growing) tuple