from functools import reduce


def get_cdf(patterns_to_frequency):
    """
    Does the CDF computation.

    Keyword args:
    patterns-to-frequency: dict of # patterns -> # occurrences
    """
    lists = sorted(patterns_to_frequency.items())
    num_patterns, frequencies = zip(*lists)
    total_modules = sum(frequencies)
    cum_frequencies = reduce(lambda c, x: c + [c[-1] + x], frequencies, [0])[1:]
    percentage_cum_frequencies =  [val * 100/ total_modules for val in cum_frequencies]
    return num_patterns, percentage_cum_frequencies