Pills coating (4 points)¶
To control the coating process of pills, a pharmaceutical company
takes data on temperature, humidity and ventilation at different
points in the production center. This data in each point is represented
in a string (str) with the following format:
'code-TEMP:t-HUM:h-air'
where code is the point code, t is the temperature, h is
the humidity and air is a string which can be ‘ON’ or ‘OFF’
indicating whether there is ventilation at that point or
not. Examples: 'AX1-TEMP:40-HUM:70-ON', 'B4-TEMP:4-HUM:9-ON',
'BRF66-TEMP:102-HUM:100-ON'. The temperature and humidity are
always positive integer values. See that the point code has a variable number of characters.
Write function control() that takes a list of strings as
described and returns a list of tuples that correspond to those points
with ventilation (i.e. if air is ‘ON’). Each tuple has three
elements: the point code (str), the temperature
(int) and the humidity (int). The list of
tuples must be sorted lexicographically, i. e., first by point code,
then by temperature and then by humidity.
Save this function to file p1.py.
Examples:
>>> control(['AX1-TEMP:43-HUM:66-ON', 'BY2-TEMP:120-HUM:100-OFF'])
[('AX1', 43, 66)]
>>> lc1 = ['AX1-TEMP:9-HUM:8-ON', 'BT3-TEMP:149-HUM:89-OFF', 'AX2-TEMP:56-HUM:45-ON', 'GH5-TEMP:59-HUM:74-OFF']
>>> control(lc1)
[('AX1', 9, 8), ('AX2', 56, 45)]
>>> lc2 = ['GH5-TEMP:59-HUM:74-ON', 'AX2-TEMP:43-HUM:67-ON', 'AX1-TEMP:62-HUM:89-ON', 'AX1-TEMP:56-HUM:45-ON']
>>> control(lc2)
[('AX1', 56, 45), ('AX1', 62, 89), ('AX2', 43, 67), ('GH5', 59, 74)]
Note
More tests are provided in file test-control.txt.