Python 将行拆分为单词任务-线性搜索方法
我的任务是将行拆分为单词,然后根据空格和换行符将行拆分。我提出了一个不完整的解决方案,因为它不会打印最后一个字。我只能使用线性搜索,因此是基本方法Python 将行拆分为单词任务-线性搜索方法,python,linear-search,Python,Linear Search,我的任务是将行拆分为单词,然后根据空格和换行符将行拆分。我提出了一个不完整的解决方案,因为它不会打印最后一个字。我只能使用线性搜索,因此是基本方法 line = raw_input() while line != "end": i = 0 while i < len(line): i = 0 while i < len(line) and line[i] == " ": i = i + 1 j = i w
line = raw_input()
while line != "end":
i = 0
while i < len(line):
i = 0
while i < len(line) and line[i] == " ":
i = i + 1
j = i
while line[j] != " ":
j = j + 1
print line[i:j]
line = line[j:]
line = raw_input()
line=原始输入()
在线时!=“结束”:
i=0
而我
我理解你的问题这有点类似于黑客的问题
请参阅此示例以阐明您的概念
如果您觉得有用,请竖起大拇指使用
string.split()
检查:空格由'
表示,换行符由'\n'
表示。您可以将其用作分割函数的参数。
y=list()
1). y=map(int,raw_input().split()) # for storing integer in list
2). y=map(str,raw_input().split()) # for storing characters of string in list
#then use this to print the value
for i in y:
print i #this loop will print one by one value
#working example of this code is #for Second part
>>baby is cute #input
>>['baby','is','cute'] #output
>> #now according to your problem line is breaks into words