Code Signal_练习题_alphabeticShift

Posted yd2018

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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)
膜拜大佬

 

以上是关于Code Signal_练习题_alphabeticShift的主要内容,如果未能解决你的问题,请参考以下文章

Code Signal_练习题_Minesweeper

Code Signal_练习题_stringsRearrangement

Code Signal_练习题_firstDigit

Code Signal_练习题_digitDegree

Code Signal_练习题_matrixElementsSum

Code Signal_练习题_alphabeticShift