逐字比较段落

Compare paragraph word by word

我正在尝试逐行逐字比较段落中的一行,但我觉得这不是最有效的方法,你能帮帮我吗? 如果有区别,我想 return 这两个词。

file_1 = open("file1.txt").readlines()
file_2 = open("file2.txt").readlines()


if file_1 == file_2:
    print("Same")
if file_1[0] != file_2 [0]:
    listone = file_1[0].split()
    listtwo = file_2[0].split()
    if listone[0] == listtwo[0] and listone[1] == listtwo[1]:
        pass
    elif listone[0] != listtwo[0] and listone[1] == listtwo[1]:
        print('line 1:\n', listone[0]+"\n", listtwo[0])
    elif listone[0] == listtwo[0] and listone[1] != listtwo[1]:
        print('line 1:\n', listone[1]+"\n", listtwo[1])

编辑:我所说的高效是指在不纠正每一行的情况下浏览整个段落。

或许您可以使用主 for 循环。这是一些解释代码。

file1 = open("file1.txt", r).readlines()
file2 = open("file2.txt", r).readlines()
for i in range(0, len(biggest_file)):
    if file[i] == file[i]:
        print("The text on line:{} is the same in both files".format(i))
    else:
        print("The text on line:{} is not the same in both files".format(i)) 

请注意,这不是工作代码,这正是系统应有的工作方式。