vgrabovets
2/27/2017 - 8:37 AM

common_words

common_words

def common_words(words_to_match_lst, text_lst):
    """
    Counts the amount of words in s1, which appeared in s2.
    Returns percent of appearence with coefficients = 1
    and weighted on length of words respectively
    """
    n_words, n_letters = 0, 0
    total_letters = 0
    for word in words_to_match_lst:
        total_letters += len(word)
        if word in text_lst:
            n_words += 1
            n_letters += len(word)
    if len(words_to_match_lst) > 0 and total_letters > 0:
        return n_words / len(words_to_match_lst), n_letters / total_letters
    else:
        return 0, 0