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()相反 –