Save Scraped Data to CSV
Given a list of scraped product records, save them to a CSV file using csv.DictWriter, then read them back and print each one.
Approach: build a list of {"title": ..., "price": ...} dictionaries, write them with csv.DictWriter (header + rows), then reopen with csv.DictReader and print each row.
Input: First line: the number of products n. Next n lines: title,price.
Output: One line per product: <title>: <price>.
2 Wireless Headphones,$49.99 Bluetooth Speaker,$29.99
Wireless Headphones: $49.99 Bluetooth Speaker: $29.99
- 1 <= n <= 100
Hint 1
csv.DictWriter(file, fieldnames=["title", "price"]) writes rows from a list of dictionaries — call writeheader() first, then writerows(products).
Hint 2
Open the file with newline="" when writing, matching the notes' own CSV convention.
Hint 3
csv.DictReader(file) reads each row back as a dictionary, keyed by the header names.
csv.DictWriter writes the header row followed by one row per product dictionary, using writeheader() then writerows(products). Reopening the file with csv.DictReader turns each row back into a dictionary keyed by "title"/"price", so printing f"{row['title']}: {row['price']}" for each one reproduces the original data.