The marketing team is spending way too much time typing in hashtags.
Let's help them with out own Hashtag Generator!
Here's the deal:
//将字符串去掉空格,以‘#’打头,并且大写每个单词的首字母。
- It must start with a hashtag (
#
). - All words must have their first letter capitalized.
- If the final result is longer than 140 chars it must return
false
. - If the input or the result is an empty string it must return
false
.
Examples
" Hello there thanks for trying my Kata" => "#HelloThereThanksForTryingMyKata"
" Hello World " => "#HelloWorld"
"" => false
mysolution:
str.title()能大写每个单词的首字母。str.capitalize()只能大写第一个单词的首字母,但是可以循环用也行。其他方案也都是这两个思路。
def generate_hashtag(s):
#your code here
s='#'+s.title().replace(' ','')
if 1<len(s)<=140:
return s
else:
return False