我必须计算必须从两个文本文件计算出的两个配置文件(两个字典的值)之间的距离。在我的程序中,我需要定义main()函数,该函数接受两个文本文件的前两个参数,三个最后一个是可选的。让我感到困惑的是,每当我传递两个不同的文件时,我每次都会得到相同的字典。
def first_file(file_one, file_two):
# it will have all the values pair except sentence and word count for the first text
one_pair = count_and_update(file_one)
# it will have average sentence and average word count for the first text
one_count = get_sent_word_count(file_one)
one_pair.update(one_count)
# it will have all the values pair except sentence and word count for the second text
second_pair = count_and_update(file_two)
# it will have average sentence and average word count for the second text
second_count = get_sent_word_count(file_two)
second_pair.update(second_count)
print(second_pair.items())
print(one_pair.items())
def main(text_file1, arg2, normalize=False):
if os.path.isfile(arg2) and normalize is False:
first_file(text_file1, arg2)
main("/Users/abhishekabhishek/downloads/l.txt", "/Users/abhishekabhishek/downloads/h.txt", False)
dict_items([('-', 1788), ("'", 3921), ('also', 3), ('although', 0), ('and', 6723), ('as', 3570), ('because', 214), ('before', 164), ('but', 821), ('for', 1238), ('if', 597), ('nor', 82), ('of', 2132), ('or', 3169), ('since', 13), ('that', 1162), ('though', 104), ('until', 3), ('when', 353), ('whenever', 8), ('whereas', 1), ('which', 118), ('while', 58), ('yet', 63), (';', 1562), (',', 8190), ('average_sentences', 0.29), ('average_words', 4.12)])
dict_items([('-', 1788), ("'", 3921), ('also', 3), ('although', 0), ('and', 6723), ('as', 3570), ('because', 214), ('before', 164), ('but', 821), ('for', 1238), ('if', 597), ('nor', 82), ('of', 2132), ('or', 3169), ('since', 13), ('that', 1162), ('though', 104), ('until', 3), ('when', 353), ('whenever', 8), ('whereas', 1), ('which', 118), ('while', 58), ('yet', 63), (';', 1562), (',', 8190), ('average_sentences', 0.29), ('average_words', 4.12)])
对于每个文件,它应该打印出不同的结果,但是打印出相同的结果