我的任务是完成一项小任务 对于只包含字符串的列表,我需要检查以下内容并创建一个列表,如果字符串中有大写字母我需要隔离该单词并将其作为单独的单词放入新列表中, 例如列表
str_list = [“This”,“is”,“not a red”,“”,“wine,but a white One”]
新的需要看起来像这样
split_str_list = [“This”,“is”,“not a”,“Red”,“”,“wine,but a white”,“One”]
非常感谢您的帮助
答案 0 :(得分:0)
str_list = ["This","is","not a Red","","Wine, but a white One"]
new_list=[]
string=''
for i in str_list:
print i
words=i.split(' ')
print words
for x in words:
if x == ' ' or x=='':
new_list.append(x)
elif x[0].isupper() and string != '':
string=string.strip()
new_list.append(string)
new_list.append(x)
string=''
elif x[0].isupper() and string == '':
new_list.append(x)
else:
string=string+x+' '
print new_list
输出:['此','不是',' Red''',' Wine, ','但是白色'一个']