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也 –