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)))
I imagine products are either objects of a certain Product
class, or are dicts, if that's the case, you can use:
discontinued
and unit_price
attributes): print(list(filter(lambda x: x.discontinued == 0 and x.unit_price > 15, products)))
discontinued
and unit_price
keys): print(list(filter(lambda x: x['discontinued'] == 0 and x['unit_price'] > 15, products)))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.