Mar-19-2020, 10:53 PM
Using the dictionary below, I'm supposed to create a function that returns the number of unique items in the "items" list.
shopping_cart = { "tax": .08, "items": [ { "title": "orange juice", "price": 3.99, "quantity": 1 }, { "title": "rice", "price": 1.99, "quantity": 3 }, { "title": "beans", "price": 0.99, "quantity": 3 }, { "title": "chili sauce", "price": 2.99, "quantity": 1 }, { "title": "chocolate", "price": 0.75, "quantity": 9 } ] }I've created the code below which outputs the number of items (5), but I need the code to only count unique items. For example, if two items in this list were identical, it should return 4 (since only 4 items would be unique in that case). How can I accomplish this?
def get_tax_rate(d): print (d['tax'])
Output:5