1
list1 = 'it is, a good,day'
我需要用逗号将字符串的所有部分分开:'it is'
,'a good'
和'day'
,然后将'ouf'
在各部分之间,因此它可以打印it is ouf a good ouf day
Python3如何单独在truple项目
注昏迷后在', a good'
之后的空间是否还有一种方法只能在逗号后删除空格?
list1 = 'it is, a good,day'
我需要用逗号将字符串的所有部分分开:'it is'
,'a good'
和'day'
,然后将'ouf'
在各部分之间,因此它可以打印it is ouf a good ouf day
Python3如何单独在truple项目
注昏迷后在', a good'
之后的空间是否还有一种方法只能在逗号后删除空格?
>>> list1 = 'it is, a good,day'
>>> ' ouf '.join(map(str.strip,list1.split(',')))
'it is ouf a good ouf day'
或者你可以尝试replace
>>> list1.replace(', ',',').replace(',',' ouf ')
'it is ouf a good ouf day'
>>> re.sub(r',\s?',' ouf ',list1)
'it is ouf a good ouf day'
我非常喜欢re模块!非常感谢你 –
@bob欢迎您!祝一切顺利。 –
@bob在这里接受http://stackoverflow.com/questions/29998421/extending-list-returns-none也 –