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

Dmitry Karamin
Dmitry Karamin
10,099 Points

Why not working?

i use this code

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

in my IDE everything in ok

i call this var

print (list(high_cal))

why it doesn't work ?

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}
]

1 Answer

rydavim
rydavim
18,814 Points

I'm not a python expert, but it looks like you might have some extra stuff in that last bit? I think you just need the list itself.

high_cal = filter(lambda data: data['calories'] > 1000, meals) # meals is the list you're using, no additional steps needed

Let me know if that doesn't work for you, or if you have questions. Happy coding!

Dmitry Karamin
Dmitry Karamin
10,099 Points

The result seems to be the same, but your version works, thanks

rydavim
rydavim
18,814 Points

Unfortunately, the challenge validation is only so good. Sometimes you need to use very specific code to get it to pass, even if other methods get you to the same answer.

Generally if it's working, but not passing for some reason, try to simplify if possible. Occasionally doing extra steps like validation and such, even if they're good practice, can also cause problems if they weren't specifically asked for.

You are correct that your code achieves the same result though. Nice job, and happy coding! :)