Guest User

Untitled

a guest
Apr 27th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. >>> "hello world".title()
  2. 'Hello World'
  3. >>> u"hello world".title()
  4. u'Hello World'
  5.  
  6. >>> "they're bill's friends from the UK".title()
  7. "They'Re Bill'S Friends From The Uk"
  8.  
  9. s = 'the brown fox'
  10. lst = [word[0].upper() + word[1:] for word in s.split()]
  11. s = " ".join(lst)
  12.  
  13. import re
  14. s = 'the brown fox'
  15.  
  16. def repl_func(m):
  17. """process regular expression match groups for word upper-casing problem"""
  18. return m.group(1) + m.group(2).upper()
  19.  
  20. s = re.sub("(^|s)(S)", repl_func, s)
  21.  
  22.  
  23. >>> re.sub("(^|s)(S)", repl_func, s)
  24. "They're Bill's Friends From The UK"
  25.  
  26. >>> ' '.join([s[0].upper() + s[1:] for s in "they're bill's friends from the UK".split(' ')])
  27. "They're Bill's Friends From The UK"
  28.  
  29. input = "they're bill's friends from the UK"
  30. words = input.split(' ')
  31. capitalized_words = []
  32. for word in words:
  33. title_case_word = word[0].upper() + word[1:]
  34. capitalized_words.append(title_case_word)
  35. output = ' '.join(capitalized_words)
Add Comment
Please, Sign In to add comment