题解 | #字符串变形#
字符串变形
http://www.nowcoder.com/practice/c3120c1c1bc44ad986259c0cf0f0b80e
class Solution:
def trans(self , s: str, n: int) -> str:
# write code here
temp = s.swapcase() # 字符串转化大小写
if temp.find(' ') == -1:
return temp # 单字符串直接返回
else:
temp = temp.split(' ')
return ' '.join(temp[::-1]) # 空格连接逆序字符串返回