Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def shopping_cart(*args):
- max_quantities = {"Soup": 3, "Pizza": 4, "Dessert": 2}
- cart = {"Soup": [], "Pizza": [], "Dessert": []}
- for command in args:
- if command == "Stop":
- break
- else:
- meal = command[0]
- product = command[1]
- if len(cart[meal]) < max_quantities[meal]:
- if product not in cart[meal]:
- cart[meal].append(product)
- for value in cart.values():
- if len(value) > 0:
- break
- else:
- return 'No products in the cart!'
- result = ""
- for meal, products in sorted(cart.items(), key=lambda item: (-len(item[1]), item[0])):
- result += f"{meal}:\n"
- for product in sorted(products):
- result += f" - {product}\n"
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement