Exercise: Finding the Customer With the Most Purchases

Use what you've learned so far to find the customer who has made the most purchases in a week.

We'll cover the following

Problem statement

You have been provided with a groceries dictionary that contains the names of the customer as the key and the number of items they bought each day in a week as a list of values.

groceries = {
    "James": [10, 2, 5, 7, 9, 4, 6],
    "Tom": [1, 12, 3, 0, 1, 2, 5],
    "Sam": [9, 5, 4, 3, 2, 1, 3], 
}

Therefore, your task is to write the most_purchases() function. This function takes in the groceries dictionary and returns the name of customer who has made the most purchases in a week, along with their total purchase.

Input

groceries = {
    "James": [10, 2, 5, 7, 9, 4, 6],
    "Tom": [1, 12, 3, 0, 1, 2, 5],
    "Sam": [9, 5, 4, 3, 2, 1, 3], 
}

Output

("James", 43)

Challenge

This problem has been designed for you to practice freely with it, so try to solve it on your own first. Take some time and think about the different concepts we’ve explored in the course so far.

If you feel stuck, you can always check out the solution review provided in the next lesson.

Good luck!

Get hands-on with 1400+ tech skills courses.