...
/Solution Review: Finding the Customer With the Most Purchases
Solution Review: Finding the Customer With the Most Purchases
This review explains the solution for the "most purchases'"problem.
We'll cover the following...
Solution
Press + to interact
def most_purchases(groceries):most_purchase_customer = Nonemax_purchases_sum = 0for key in groceries:curr_sum = sum(groceries[key])if curr_sum > max_purchases_sum:max_purchases_sum = curr_summost_purchase_customer = keyreturn (most_purchase_customer, max_purchases_sum)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],}customer_results = most_purchases(groceries)print(customer_results)
Explanation
The first thing we need to do is create two new variables: most_purchase_customer
and max_purchases_sum
at lines 2 to 3 respectively. These will be used to store the name of the customer who made ...