我有一个看起来像这样的列表:
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]