How Do I Check If There Is A Uppercase Letter In A String Within A List Of Strings?
I have a list of words: str_list = [“There”, “is”, “ a Red”, “”, “shirt, but not a white One”] I want to check if there is a capital letter in every word in th
Solution 1:
You can use re.split()
:
import re
importitertoolsstr_list= ['There', 'is', ' a Red', '', 'shirt, but not a white One']
final_data = list(itertools.chain.from_iterable([re.split('\s(?=[A-Z])', i) for i in str_list]))
Output:
['There', 'is', ' a', 'Red', '', 'shirt, but not a white', 'One']
Post a Comment for "How Do I Check If There Is A Uppercase Letter In A String Within A List Of Strings?"