def lexical_density(words_list, lexi_file_name):
    " calculates the lexical density.\n    L_d = (N_lex / N) * 100\n    Where:\n\n    L_d = the analyzed text's lexical density\n\n    N_lex = the number of lexical word tokens (nouns,adjectives,verbs,adverbs)\n    in the analyzed text.\n\n    N = the number of all tokens (total number of words) in the analyzed text.\n    "
    l_d = 0
    n_lex = 0
    n = 0
    with open(lexi_file_name, 'r', encoding=DEFAULT_CODEC) as fp:
        lexical_words = fp.read()
    lexical_words = lexical_words.split(',')
    for word in lexical_words:
        counter = words_list.count(word)
        n_lex += counter
        counter = 0
    n = len(words_list)
    l_d = ((n_lex / n) * 100)
    return l_d
calculates the lexical density.
L_d = (N_lex / N) * 100
Where:

L_d = the analyzed text's lexical density

N_lex = the number of lexical word tokens (nouns,adjectives,verbs,adverbs)
in the analyzed text.

N = the number of all tokens (total number of words) in the analyzed text.
def lexical_density(words_list, lexi_file_name):
    " calculates the lexical density.\n    L_d = (N_lex / N) * 100\n    Where:\n\n    L_d = the analyzed text's lexical density\n\n    N_lex = the number of lexical word tokens (nouns,adjectives,verbs,adverbs)\n    in the analyzed text.\n\n    N = the number of all tokens (total number of words) in the analyzed text.\n    "
    l_d = 0
    n_lex = 0
    n = 0
    with open(lexi_file_name, 'r', encoding=DEFAULT_CODEC) as fp:
        lexical_words = fp.read()
    lexical_words = lexical_words.split(',')
    for word in lexical_words:
        counter = words_list.count(word)
        n_lex += counter
        counter = 0
    n = len(words_list)
    l_d = ((n_lex / n) * 100)
    return l_d