问题描述
您好。我有一个字符串,如''LNAME
PASTA ZONE''。我想创建一个单词列表和
基本上用一个空格替换它们之间的所有空格,所以我可以用lala.split()来实现
。谢谢!
Ryan Kaskel
Hello. I have a string like ''LNAME
PASTA ZONE''. I want to create a list of those words and
basically replace all the whitespace between them with one space so i
could just do lala.split(). Thank you!
Ryan Kaskel
推荐答案
你*可以*只做``lala.split()``:
在[97]:lala =''LNAME PASTA ZONE''
在[98]中:lala.split()
Out [98]:[''LNAME'', ''PASTA'',''ZONE'']
Ciao,
Marc''BlackJack''Rintsch
You *can* just do ``lala.split()``:
In [97]: lala = ''LNAME PASTA ZONE''
In [98]: lala.split()
Out[98]: [''LNAME'', ''PASTA'', ''ZONE'']
Ciao,
Marc ''BlackJack'' Rintsch
import re
s =''LNAME PASTA ZONE''
re.split(''\ s +'',s)
import re
s = ''LNAME PASTA ZONE''
re.split(''\s+'', s)
所以当你进入Python交互式提示并首先打字时
lala =''LNAME PASTA ZONE''
然后
lala.split()
你看到了什么,以及什么您还需要更多满足您的要求吗?
So when you go to the Python interactive prompt and type firstly
lala = ''LNAME PASTA ZONE''
and then
lala.split()
what do you see, and what more do you need to meet your requirements?
这篇关于剥离空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!