def get_topics(topics, mode='p', top=0.5):
    """
    Returns the top topics from a list of topics with corresponding probabilities
    :param topics: list of tuples (topic, double)
            List of the topics with corresponding probabilities
    :param mode: str, optional
            If 'p' top percentage of topics will be considered
            If 'n' top number of topics will be considered
            Default to 'p'
    :param top: double, optional
            If mode = 'p' the top topics having their probability sum > top will be chosen
            If mode = 'n' the top top many topics will be chosen
            Default to 0.5
    :return:
        t: list
         List containing the top topics
    """
    t = sorted(topics, key=lambda x: x[1], reverse=True)
    t2 = []
    s = 0
    i = 0
    if mode == 'p':
        while s < top and i < len(t):
            t2.append(t[i])
            s += t[i][1]
            i += 1
    elif mode == 'n':
        while i < top and i < len(t):
            t2.append(t[i])
            i += 1
    return t2