重新创建句子时代码中的逻辑错误(python)

时间:2017-04-01 17:46:45

标签: python json error-handling logic

所以我有一个程序可以查看.txt文件中的句子。然后程序找到句子中每个单词的位置以及句子中的唯一单词。这两个列表在程序中输出,然后程序尝试根据句子中的唯一单词和句子中单词的位置重新创建.txt文件中的原始句子,然后应该在程序中输出。我到目前为止的代码如下所示:

Please enter an existing compressed file to be decompressed: ohdear
Words in the sentence: ['hello', 'hello', 'hello', 'hello']
Unique words: ['hello']
The positions of the word(s) in the sentence are: [1, 1, 1, 1]
Original sentence from file: h h h h

现在描述一个示例测试。假设有一个名为'ohdear'的.txt文件,其中包含句子:“hello hello hello hello”

现在程序如下所示:

{{1}}

正如你所看到的,原始句子并没有从句子中单词和单词的位置重新创建 - 奇怪地显示了4小时。有人可以帮助解决这个错误,因为我不知道如何从句子中单词和单词的位置重新创建原始句子。问题出在OutputDecompressed2()函数中。在此先感谢您的帮助。

0 个答案:

没有答案