有没有一种方法可以基于“ n”获取一个句子的所有可能的difflib.get_close_matches?

时间:2019-05-02 03:27:28

标签: python-3.x difflib

所以我在difflib.get_close_matches库上的代码有问题,我想获取句子中所有可能的单词匹配。

    def nearest_words(sentence,n):
        global tagalog_dictionary
        global index
        index = 0
        sentences = sentence.split()
        sentence_s = sentence
        temp_sentence = ' '
        counter = 0
        new_sentence = list()

        elif int(n) > 1:
            word_l = 0
            for i in range(n):
                for words in sentences:
                        x = difflib.get_close_matches(words, get_all_matches_list, int(n))[i]
                        print(x)
                        new_sentence.append(x)
                        counter += 1

            print(new_sentence)

Sample sentence = "dis iz a gud music"

if n = 4

output based on N:

Output 1 = " this is a good music" <br>
Output 2 = " ths isz aw gd music" <br>
Output 3 = ........<br>
Output 4 = ........

0 个答案:

没有答案