Given a string, replace each its character by the next one in the English alphabet (z
would be replaced by a
).
Example
For inputString = "crazy"
, the output should bealphabeticShift(inputString) = "dsbaz"
.
我的解答:
def alphabeticShift(inputString): l = [] for x in inputString: l.append(x) for i in range(len(inputString)): if l[i] == ‘z‘: l[i] = ‘a‘ else: l[i] = chr(ord(l[i])+1) return ‘‘.join(l)
def alphabeticShift(s): return "".join(chr((ord(i)-96)%26+97) for i in s)
膜拜大佬
原文地址:https://www.cnblogs.com/YD2018/p/9470327.html
时间: 2024-10-13 01:18:45