from functools import reduce
from operator import truediv


def analyze(sample_paragraph, typed_string, start_time, end_time):
    """Returns a list containing two values:
    words per minute and accuracy percentage.

    This function takes in a string sample_paragraph,
    a string provided by user input typed_string,
    a number start_time and
    a number end_time.

    Both start_time and end_time are measured in seconds. 
    """

    num_of_wrds = len(typed_string) / 5

    try:
        wrds_per_min = num_of_wrds / (end_time - start_time) * 60
    except ZeroDivisionError:
        wrds_per_min = float('Inf')

    words_pair = zip(sample_paragraph.split(), typed_string.split())
    alg = lambda cnt_length, sp_ts: (cnt_length[0] + (sp_ts[0] == sp_ts[1]), cnt_length[1] + 1)  # the algebra for catamorphism

    try:
        accuracy = truediv(*reduce(alg, words_pair, (0, 0))) * 100
    except ZeroDivisionError:
        accuracy = 0.0

    return [wrds_per_min, accuracy]