Objects File¶
We consider a textfile with information about some objects marked with different prices.
The format of these files is as follows:
The fist line contains the header.
Each of the following lines contains the info about one object and a price found. The same object might appear several times with different colors and prices. Each line has the following infos separated by coma (
','):
The file objects14.csv is an example:
NAME,ID,COLOR,UNITS,PRICE box,11,red,2.0 tree,23,yellow,1.60 table,31,blue,1.45 lamp,44,red,2.25 chair,51,blue,0.5 bed,69,blue,3.5 tree,23,yellow,1.85 spoon,77,red,3.55 tree,23,yellow,1.8 box,11,red,2.5 chair,51,blue,0.75 table,31,blue,1.05 chair,51,blue,0.25 bed,69,blue,4.0
You are required to delivered the following function in the module objects_file (file objects_file.py):
- read_objects(filename)¶
such that
For example the call read_objects('objects14.csv') over the previous file should produce the following dict:
>>> solD = { ... ('box', 11): ['red', 2, 2.25], ... ('tree', 23): ['yellow', 3, 1.75], ... ('table', 31): ['blue', 2, 1.25], ... ('lamp', 44): ['red', 1, 2.25], ... ('chair', 51): ['blue', 3, 0.5], ... ('bed', 69): ['blue', 2, 3.75], ... ('spoon', 77): ['red', 1, 3.55], ... }
Find the doctest file at read_objects.test.