Queer European MD passionate about IT

grocery.py 404 B

12345678910111213141516
  1. def main():
  2. shopping_list = {}
  3. while True:
  4. try:
  5. item = input("").upper()
  6. except EOFError:
  7. break
  8. if item not in shopping_list:
  9. shopping_list[item] = 0
  10. shopping_list[item] += 1
  11. for item, quantity in sorted(shopping_list.items(), key=lambda x: x[0]):
  12. print(f"{quantity} {item}")
  13. if __name__ == "__main__":
  14. main()