题解 | #字符串变形#
字符串变形
https://www.nowcoder.com/practice/c3120c1c1bc44ad986259c0cf0f0b80e
#直接用split()碰到空格开头或结尾的会少一个空字符串,要用split(' ') class Solution: def trans(self, s, n): l = s.split(' ') l = l[::-1] s = "" for letter in l: letter = letter.swapcase() # 调整大小写 s += letter # 重新串成一个字符串 s += ' ' return s[0:len(s)-1]