Separate¶
Let’s consider a non-empty list of float numbers. We want to process the numbers up to a given number is found (this let’s call it the mark) and separate these numbers into 2 lists of integers: one list with their integer parts and another list with their decimal parts (rounded to 2 decimals). If the mark is not found in the list then all numbers will be processed. Moreover, both resulting lists must be ordered increasingly.
Implement the following Python function in the module separate (file separate.py):
For example:
>>> ln1 = [5.65, 3.35, 9.54, 6.25, 2.5, 0.0, 1.5, 2.1] >>> li1, ld1 = separate(ln1, 0.0) >>> li1 == [2, 3, 5, 6, 9] and ld1 == [0.25, 0.35, 0.5, 0.54, 0.65] True >>> ln1 = [5.65, 3.35, 9.54, 6.25] >>> li1, ld1 = separate(ln1, 0.0) >>> li1 == [3, 5, 6, 9] and ld1 == [0.25, 0.35, 0.54, 0.65] True
Doctests are available at the separate-test.txt file.