代码之家  ›  专栏  ›  技术社区  ›  איתי שולמן

检查列表内字符串中的大写字母

  •  -2
  • איתי שולמן  · 技术社区  · 7 年前

    我的任务是做一个小任务 例如列表

    str_list=[这不是红葡萄酒,而是白葡萄酒]

    新的应该像这样

    split\u str\u list=[这不是一种红葡萄酒,而是一种白葡萄酒,一种]

    非常感谢你的帮助

    1 回复  |  直到 7 年前
        1
  •  0
  •   sanch    7 年前
    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
    

    输出:[“This”,“is not a”,“Red”,“Wine”,“but a white”,“One”]