Whats the average spend per customer (including customers too who haven't purchased anything)?
Asked in the phone interview stage. Implement the calculation without SQL.
Implement average_spend(customers, purchases). customers is a non-empty list of unique customer IDs. purchases is a list of [customer_id, amount] pairs. Return the total amount from purchases belonging to known customers divided by the number of customers. Customers without purchases contribute zero. Ignore purchases for unknown customer IDs.
def average_spend(customers, purchases):