问题:
给一个句子,比如 "How can mirrors be real if our eyes aren't real" 。
写一个程序转换为, "How Can Mirrors Be Real If Our Eyes Aren't Real"。
思路:
把除了第一个单词的所有单词转换为大写即可。
代码:
def toJadenCase(string):
# ...
s = string.split()
diff = abs(ord('a') - ord('A'))
result = []
for i in xrange(1,len(s)):
t = chr(ord(s[i][0]) - diff)
result.append(t + s[i][1:])
return s[0] + ' ' + ' '.join(result)
#toJadenCase("How can mirrors be real if our eyes aren't real")