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

Qian Chen
Qian Chen
33,579 Points

I don't understand why the long_total function

I understand long_total is a bad example. But if it is to calculate the total price of a list of books, why not use a for loop? The long_total example does not seem to make sense to me. Or I just totally missed the idea of something.

I actually had the same comment. In fact, why not just go with:

print(sum(b.price for b in BOOKS))

This seems to do the same calculation in a much cleaner way. Can anyone explain the advantage of using the reduce method in that example? Thanks