0
我如何得到这个程序将文件压缩成单词列表和位置列表来重新创建原始文件。然后取出压缩文件并重新创建原始文件的全文,包括标点符号和大写字母。我该如何解决这个问题?
startsentence = input("Please enter a sentence: ")
sentence = (startsentence)
a = startsentence.split(" ")
dict = dict()
number = 1
positions = []
for j in a:
if j not in dict:
dict[j] = str(number)
number = number + 1
positions.append(dict[j])
print (positions)
print(positions)
f = open("postions.txt", "w")
f.write(str(positions) + "\n" )
f.close()
print(sentence)
f = open("words.txt", "w")
f.write(str(startsentence) + "\n" )
f.close()
你有问题吗? – DeepSpace
对不起,我说错了,一秒钟。 –
不要使用'dict'作为你隐藏标准python'dict'类型的变量名。 – AChampion