用下划线连接用引号引起来的多个字符串

时间:2019-03-12 22:30:31

标签: python string list

我有一个看起来像这样的列表:

list = ["My Strings to be Combined" "More Strings"]

我想变成这样:

new_list = ["My_Strings_to_be_Combines, More_Strings]

我该怎么做?我当时正在考虑做这样的事情,但是正则表达式可能更适合:

#select word between quotation marks 
for i in list:
new_list_elements= i[(i.index('"')+len('"')):i.index('"')]

#repalce spaces with underscore
new_list= [words.replace(' ','_') for words in my_string]

0 个答案:

没有答案