Divide

Let’s consider a non-empty list of int numbers. We want to process the numbers up to a given number (this let’s call it the mark) and separate these numbers into 2 lists: one list with the numbers above or equal than the average of all numbers in the given list, and another with the ones under the average. If the mark is not found in the list then all numbers will be processed. Moreover both lists must additionally have at the end a float number corresponding to the average of its values, rounded to 1 decimal.

Implement the following Python functions in the module divide (file divide.py). Starting with the second one is recommended.

The first function is:

divide(ln, mark)
takes ln a non-empty list of int, and mark an arbritary int.
returns 2 lists of int according to the description above.

For exemple:

>>> divide([3, -2, 7, 0, 2], 0)
([3, 7, 5.0], [-2, -2.0])

>>> divide([3, -2, 7, 0, 2], -1)
([3, 7, 2, 4.0], [-2, 0, -1.0])

>>> divide([1], 0)
([1, 1.0], [0.0])

Doctests are available at the divide-test.txt file.

This function must call the following function:

add_avg(ln)
takes ln a (might be empty) list of int.
modifies ln by adding the average of its values at the end (must be a float rounded to 1 decimal).

For exemple:

>>> l = [3, 7]
>>> add_avg(l)
>>> l == [3, 7, 5.0]
True
>>> l = [-2]
>>> add_avg(l)
>>> l == [-2, -2.0]
True
>>> l = [3, 7, 2]
>>> add_avg(l)
>>> l == [3, 7, 2, 4.0]
True
>>> l = [-2, 0]
>>> add_avg(l)
>>> l == [-2, 0, -1.0]
True
>>> l = []
>>> add_avg(l)
>>> l == [0.0]
True

Doctests are available at the add_avg-test.txt file.