Grocery shopping

Report a typo

Every Sunday Jane goes to a local market to buy groceries for the upcoming week. When she makes her shopping list, she never puts everything down at once: she keeps track of what she wants to buy during the day. On Sunday morning her list looked like this:

to_buy = ['carrots', 'carrots', 'bread', 'tomatoes', 'onions', 'apples', 'tomatoes', 'carrots', 
          'tomatoes', 'onions', 'onions', 'onions', 'bread', 'milk', 'bread', 'apples']

Write a program that prints what she wants to buy and how many times she has added it to her shopping list, like in the example. The order of the items should be preserved.

Sample Input 1:

carrots carrots bread tomatoes onions apples tomatoes carrots tomatoes onions onions onions bread milk bread apples

Sample Output 1:

3 carrots
3 bread
3 tomatoes
4 onions
2 apples
1 milk
Write a program in Python 3
shopping_list = input().split()
___

Create a free account to access the full topic