0

Only include products that are non-discontinued (discontinued=0) with unit_price greater than 15.0 in the new list. How I can solve this? How can I select and use discontinued=0 with unit_price and put it into the code?

print (list(filter(lambda x: x=0,>15,products)))
1

1 Answer 1

2

I imagine products are either objects of a certain Product class, or are dicts, if that's the case, you can use:

For objects of a certain class (having discontinued and unit_price attributes):

print(list(filter(lambda x: x.discontinued == 0 and x.unit_price > 15, products)))

For dicts (having discontinued and unit_price keys):

print(list(filter(lambda x: x['discontinued'] == 0 and x['unit_price'] > 15, products)))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.