Objects¶
Let’s consider a dictionary with information about a number of objects with the following format:
For example:
>>> objD = { ... ('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], ... }
You are required to deliver the following functions in the module objects (file objects.py).
The first function is:
- list_objects(objD)¶
such that
For example:
>>> l = list_objects(objD) >>> solL = [ ... ('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), ... ]
Warning
This function must be implement using comprehension lists.
Doctests are available in the list_objects.test file.
The second function is:
- sort_objects(L)¶
such that
For example:
>>> solL = [ ... ('bed', 69, 'blue', 2, 3.75), ... ('table', 31, 'blue', 2, 1.25), ... ('chair', 51, 'blue', 3, 0.5), ... ('spoon', 77, 'red', 1, 3.55), ... ('lamp', 44, 'red', 1, 2.25), ... ('box', 11, 'red', 2, 2.25), ... ('tree', 23, 'yellow', 3, 1.75) ... ]
Warning
This input list must not be modified by the function.
Doctests are available in the sort_objects.test file.