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!

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

Andy Hughes
Andy Hughes
8,127 Points

Reduce challenge - Where did ‘add’ come from?

Just started the ‘reduce()’ challenge task and on step 4 it says to use ‘(and add)’. I figured it out after searching the community answers.

But I still can’t find where ‘add’ is referenced in the videos before? Was it from a long ways back or was I supposed to just go search ‘add’ to figure it out somehow.

It feels a little like we didn’t talk about it in the video, but hey use this!

I’m sure it’s me that’s missed it because it was talked about way back, but I have searched and can’t find it in the previous lessons.

It sure would be useful to make reference to previous videos when doing this sort of thing. I get that we need to learn to figure stuff out, but a link to a video that might contain something useful in overcoming a code challenge, would be super helpful. :)

from operator import add
from functools import reduce

prices = [
    (6.99, 5),
    (2.94, 15),
    (156.99, 2),
    (99.99, 4),
    (1.82, 102)

def product_sales(tpl):
    return tpl[0] * tpl[1]

total = reduce(add, map(product_sales, prices))

1 Answer

Thanks for the feedback Andy Hughes! You're right, it was not mentioned in the previous videos and it looks like Kenneth was trying to teach your how to do it during the code challenge. I will pass on the feedback to the team!

Andy Hughes
Andy Hughes
8,127 Points

Thank you Mel Rumsey. I do know that sometimes the videos make reference to content from older videos and it’s easy to forget where you learned something as you’re whizzing through the course. Thanks for your response. :)