0

hello pals,
I need a help with using re module to search and convert uppercase words in a string to title case
Eg:

mystr='Hello everybody. Some times THERE ARE upper case words'
#Results should be 'Hello everybody. Some times There Are upper case words'

Hope you can give a hand to solve this.

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by kasunc
0

Something like this could do it:

mystr = 'Hello everybody. Some times THERE ARE upper case words'
mylist = mystr.split()
#print mylist

newstr = ''
for word in mylist:
    if word[0].isupper():
        word = word.capitalize()
    newstr += word + ' '

print newstr

"""
my output -->
Hello everybody. Some times There Are upper case words
"""
0

Thank you every much. Problem solved. I thought I have to use regex. :D

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.