0
我想從我的名單上單獨的行打印每一個字,但它是打印出每一個字母到各行如何在列表中打印單個單詞?
Words = sentence.strip()
for word in sentence:
print (word)
我完整的代碼(任何人都知道)是:
import csv
file = open("Task2.csv", "w")
sentence = input("Please enter a sentence: ")
Words = sentence.strip()
for word in sentence:
print (word)
for s in Words:
Positions = Words.index(s)+1
file.write(str(Words) + (str(Positions) + "\n"))
file.close()
使用'.split()'和'.strip()' –
有關問題請使用http://codereview.stackexchange.com – esote
不要使用'.index()'作爲位置,只返回第一個位置(如果你有重複的字母),使用'enumerate()相反 –