sentence = raw_input("Enter a sentence: ")
sentence = sentence.lower().split()
uniquewords = []
for word in sentence:
if word not in uniquewords:
uniquewords.append(word)
positions = [uniquewords.index(word) for word in sentence]
recreated = " ".join([uniquewords[word] for word in positions])
positions = [x+1 for x in positions]
print uniquewords
print positions
print recreated
file = open('task2file1.txt', 'w')
file.write('\n'.join(uniquewords))
file.close()
file = open('task2file2.txt', 'w')
file.write('\n'.join(positions))
file.close()
これは、これまで私が持っているコードであり、すべてがテキストファイルに位置を保存する以外に動作し、私が取得エラーメッセージが保存番号
"file.write('\n'.join(positions))
TypeError: sequence item 0: expected string, int found"
は、Google検索にエラーメッセージを貼り付けてみましたか? – TigerhawkT3