检查列表中字符串中的大写字母
Checking for an uppercase in strings inside a list
我接到了一个小任务
对于仅包含字符串的列表,我需要检查以下内容并创建一个列表,如果字符串中有大写字母,我需要隔离该单词并将其作为单独的单词放入新列表中,
例如列表
str_list = [“这个”,“是”,“不是红酒”,“”,“酒,而是白酒”]
新的需要像这样
split_str_list = [“这个”,“是”,“不是”,“红”,“”,“酒,而是白的”,“一个”]
非常感谢您的帮助
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
OUTPUT:['This', 'is not a', 'Red', '', 'Wine,', 'but a white', 'One']
我接到了一个小任务 对于仅包含字符串的列表,我需要检查以下内容并创建一个列表,如果字符串中有大写字母,我需要隔离该单词并将其作为单独的单词放入新列表中, 例如列表
str_list = [“这个”,“是”,“不是红酒”,“”,“酒,而是白酒”]
新的需要像这样
split_str_list = [“这个”,“是”,“不是”,“红”,“”,“酒,而是白的”,“一个”]
非常感谢您的帮助
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
OUTPUT:['This', 'is not a', 'Red', '', 'Wine,', 'but a white', 'One']