2016-09-13 3 views
-4
sentence = "ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU ASK WHAT YOU CAN DO FOR YOUR COUNTRY" 
s = sentence.split() 
another = [0] 
print(sentence) 
for count, i in enumerate(s): 
    if s.count(i) < 2: 
     another.append(max(another) + 1) 
    else: 
     another.append(s.index(i) +1) 
another.remove(0) 
print(another) 

答えて

0

私は文章をテキストファイルに入れたいと思っていますか?その場合、コードは次のとおりです。

text_file = ("textfile.txt", "w") 
text_file.write(sentence) 
text_file.close() 

textfile.txtがプログラムと同じフォルダにあることを確認してください。

関連する問題