Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Functional Python The Lambda Lambada Reduce

Andy Hughes
Andy Hughes
8,114 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. :)

prices.py
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

Mel Rumsey
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Mel Rumsey
Treehouse Staff

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,114 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. :)