0
我有這段代碼來找到第一次出現這個詞的位置,並將其替換爲實際的程序。 我已經嘗試過這種這段代碼的輸出需要發送到一個單獨的文本文件,爲什麼沒有工作
sentence = "ask not what you can do for your country ask what your country can do for you"
listsentence = sentence.split(" ")
d = {}
i = 0
values = []
for i, word in enumerate(sentence.split(" ")):
if not word in d:
d[word] = (i + 1)
values += [d[word]]
print(values)
example = open('example.txt', 'wt')
example.write(str(values))
example.close()
我怎樣寫這個輸出到一個單獨的文本文件,如記事本。
記事本是一個應用程序,而不是一個文本文件... – poke