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 Lambda

Krishna Desai
Krishna Desai
7,977 Points

This appears to return the right values in my local interpreter, why doesn't it work on Treehouse?

I verified in my local python interpreter that the return value = [{'name': 'large pizza', 'calories': 1500}, {'name': 'burrito', 'calories': 1050}]

However, I'm getting a "Bummer: did you use filter and lambda?" error on Treehouse.

meals.py
meals = [
    {'name': 'cheeseburger',
     'calories': 750},
    {'name': 'cobb salad',
     'calories': 250},
    {'name': 'large pizza',
     'calories': 1500},
    {'name': 'burrito',
     'calories': 1050},
    {'name': 'stir fry',
     'calories': 625}
]

high_cal = list(filter(lambda x: x['calories'] > 1000, meals))

1 Answer

Try without list

Krishna Desai
Krishna Desai
7,977 Points

That did it. Thanks.

I had initially used

high_cal = filter(lambda x: x, [meal for meal in meals if meal['calories'] > 1000])

which also threw the same error.. oh well. Least I was close.