拆分句子成词用空格分开 [英] Split sentence into words separated by space
本文介绍了拆分句子成词用空格分开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个查询栏,基本上需要输入;
I have a query bar which basically takes input;
alpha = raw_input('Give me text: ')
如果alpha是一个句子我希望它它拆分成词,并把它们在一个列表;
If alpha is a sentence i want it to split it into words and put them in a list;
word[1] = "What"
word[2] = "is"
word[3] = "Life"
.....
因此,对
我想用()运行一个for循环和分裂。但我敢肯定有一个更简单的方法。干杯!
I was thinking about running a for loop and splitting with (" "). But i'm sure there's an easier way. Cheers!
推荐答案
就叫 alpha.split()
,它会给你你正在寻找什么
Just call alpha.split()
and it'll give you exactly what you're looking for:
In [1]: "What is Life".split()
Out[1]: ['What', 'is', 'Life']
(请记住列表指数起始于零,而不是一个作为你的榜样。)
(Bear in mind that list indices start at zero and not one as in your example.)
这篇关于拆分句子成词用空格分开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文