Code Signal_练习题_alphabeticShift

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 be
alphabeticShift(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)
膜拜大佬

猜你喜欢

转载自www.cnblogs.com/YD2018/p/9470327.html
今日推荐