bcb-0007
1.000
Proposed solution
```python
import csv
import collections
import operator
def task_func(csv_file_path):
"""
Find the best-selling product from a given CSV file with sales data.
This function parses a CSV file assumed to have a header followed by rows containing
two columns: 'product' and 'quantity'. It computes the total sales per product and
determines the product with the highest cumulative sales. The CSV file must include
at least these two columns, where 'product' is the name of the product as a string
and 'quantity' is the number of units sold as an integer.
Args:
csv_file_path (str): The file path to the CSV file containing sales data.
Returns:
str: The name of the top-selling product based on the total quantity sold.
Requirements:
- csv
- collections
- operator
Example:
>>> task_func("path/to/sales.csv")
'Product ABC'
"""
product_sales = collections.defaultdict(int)
with open(csv_file_path, newline='') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
product_sales[row['product']] += int(row['quantity'])
top_selling_product = max(product_sales.items(), key=operator.itemgetter(1))[0]
return top_selling_product
```Test output (stdout)
....... [100%] 7 passed in 0.02s
System prompt
You are an expert programmer. Solve the task exactly as specified. Output your solution as fenced code blocks using the required file name(s) and the exact function/type signatures requested. Prefer correctness; do not include prose outside code unless asked.