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 trialamalsree
2,396 Pointsexpected 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
Alexander Davison
65,469 PointsPlease format your code properly. Read the Markdown Cheatsheet below the answer box
Ross Coe
5,061 Pointsprod x*y no?! you're currently returning a (growing) tuple
amalsree
2,396 Pointsamalsree
2,396 Pointsdone!