Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def capitalize(s):
- s.title()
- s[len(s) - 1].upper()
- return s
- def capitalize(s):
- s, result = s.title(), ""
- for word in s.split():
- result += word[:-1] + word[-1].upper() + " "
- return result[:-1] #To remove the last trailing space.
- print capitalize("i like cats")
- I LikE CatS
- capEnds = lambda s: (s[:1].upper() + s[1:-1] + s[-1:].upper())[:len(s)]
- ' '.join(map(capEnds, 'I like cats'.split(' ')))
- 'I LikE CatS'
- def upup(s):
- if len(s) < 2:
- return s.upper()
- return ''.join((s[0:-1].title(),s[-1].upper())))
- ' '.join(upup(s) for s in 'i like cats'.split())
- Out[7]: 'I LikE CatS'
- def cap_both(phrase):
- return ' '.join(map(lambda s: s[:-1]+s[-1].upper(), phrase.title().split()))
- >>> cap_both('i like cats')
- 'I LikE CatS'
- >>> cap_both('a')
- 'A'
- >>> words= words.split()
- >>> words = [capitalize(x) for x in words]
- >>> words = " ".join(words)
- def capitalize(word):
- return word[0].capitalize() + word[1:-1] + word[-1].capitalize()
- string = 'this is a test string'
- def Capitalize(st):
- for word in st.split():
- newstring = ''
- if len(word) > 1:
- word = word[0].upper() + word[1:-1] + word[-1].upper()
- else:
- word = word[0].upper()
- newstring += word
- print(word)
- Capitalize(st)
Add Comment
Please, Sign In to add comment