Intermediate
Total a CSV column
Write total_by_item(text) for CSV text with the header item,qty. Return a dict mapping each item to the sum of its qty values (as integers).
Rows whose qty is not a whole number (for example x) must be skipped. Use csv.DictReader and io.StringIO (it lets DictReader read from a string as if it were a file). Hint: all values from CSV are text.
What Check tests
- Sums repeated items
- Skips bad quantities
- Quoted commas stay inside the value
- Only a header gives an empty dict
- Blank and decimal quantities are skipped
- An item with only bad rows is not listed
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.