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的更多相关文章

  1. Code Signal_练习题_digitDegree

    Let's define digit degree of some positive integer as the number of times we need to replace this nu ...

  2. Code Signal_练习题_Knapsack Light

    You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...

  3. Code Signal_练习题_growingPlant

    Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...

  4. Code Signal_练习题_arrayMaxConsecutiveSum

    Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...

  5. Code Signal_练习题_differentSymbolsNaive

    Given a string, find the number of different characters in it. Example For s = "cabca", th ...

  6. Code Signal_练习题_firstDigit

    Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...

  7. Code Signal_练习题_extractEachKth

    Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...

  8. Code Signal_练习题_stringsRearrangement

    Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...

  9. Code Signal_练习题_absoluteValuesSumMinimization

    Given a sorted array of integers a, find an integer x from a such that the value of abs(a[0] - x) + ...

随机推荐

  1. Swift5 语言指南(二十六) 内存安全

    默认情况下,Swift可以防止代码中发生不安全行为.例如,Swift确保变量在使用之前进行初始化,在取消分配后不访问内存,并检查数组索引是否存在越界错误. Swift还确保对同一内存区域的多次访问不会 ...

  2. linux 服务器脚本采集数据中文无法执行错误

    问题描述:在 RHEL6 版本的服务器上使用脚本操作数据库,其中一个SQL的字段值为中文,每次使用 crontab定时 执行该脚本无法获取数据,实现预期效果,而手动执行正常. oracle clien ...

  3. log4j的日志级别(ssm中log4j的配置)

    log4j定义了8个级别的log(除去OFF和ALL,可以说分为6个级别),优先级从高到低依次为:OFF.FATAL.ERROR.WARN.INFO.DEBUG.TRACE. ALL. 1. ALL ...

  4. POJ 2864

    #include <iostream> #define MAXN 600 using namespace std; int _m[MAXN][MAXN]; int main() { //f ...

  5. Linux命令对应的英文全称

    su:Swith user  切换用户,切换到root用户cat: Concatenate  串联uname: Unix name  系统名称df: Disk free  空余硬盘du: Disk u ...

  6. Numpy 常用矩阵计算函数

    基本属性 在做一些数据分析的时候,我们通常会把数据存为矩阵的形式,然后python本身对于矩阵的操作是不够的,因此出现了numpy这样一个科学开发库来进行python在次上面的不足. Numpy's ...

  7. spring 后处理器

    Bean后处理器 新建maven项目并添加spring依赖,目录结构如下 Axe public interface Axe { public String chop(); } Person publi ...

  8. 【转】获取到元素的 offsetLeft 、offsetTop属性不正常的解决方法。

    原地址:http://hi.baidu.com/huidust520/item/85da006981a6c635ad3e834e 我在工作中遇到个问题: 在ie7下和360浏览器下获取到的  offs ...

  9. php还原16进制特殊字符

    特殊字符的16进制表:https://websitebuilders.com/tools/html-codes/ascii/ 可以通过 hexdec() 和 chr()方法来进行转换, 例子: < ...

  10. jquery的DataTable按列排序

    不管你用SQL查询数据时,是如何排序的,当数据传递给DataTable时,它会按照它自己的规则再进行一次排序,这个规则就是"order" 可以使用以下代码来进行排序 $('#exa ...