Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> "hello world".title()
- 'Hello World'
- >>> u"hello world".title()
- u'Hello World'
- >>> "they're bill's friends from the UK".title()
- "They'Re Bill'S Friends From The Uk"
- s = 'the brown fox'
- lst = [word[0].upper() + word[1:] for word in s.split()]
- s = " ".join(lst)
- import re
- s = 'the brown fox'
- def repl_func(m):
- """process regular expression match groups for word upper-casing problem"""
- return m.group(1) + m.group(2).upper()
- s = re.sub("(^|s)(S)", repl_func, s)
- >>> re.sub("(^|s)(S)", repl_func, s)
- "They're Bill's Friends From The UK"
- >>> ' '.join([s[0].upper() + s[1:] for s in "they're bill's friends from the UK".split(' ')])
- "They're Bill's Friends From The UK"
- input = "they're bill's friends from the UK"
- words = input.split(' ')
- capitalized_words = []
- for word in words:
- title_case_word = word[0].upper() + word[1:]
- capitalized_words.append(title_case_word)
- output = ' '.join(capitalized_words)
Add Comment
Please, Sign In to add comment