[关闭]
@aloyschen 2017-09-27T03:08:50.000000Z 字数 460 阅读 111

CodeWars 刷题

codewars

2017.09.25

Replace With Alphabet Position

In this kata you are required to, given a string, replace every letter with its position in the alphabet.

If anything in the text isn't a letter, ignore it and don't return it.

a being 1, b being 2, etc.

As an example:

alphabet_position("The sunset sets at twelve o' clock.") Should
return "20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3
12 15 3 11" as a string.


知识点

1. python可以通过ord获取字符的asci码;
2. python的for...[if]语句可以返回符合条件的list;
3. python的字符串函数isalpha可以判断英文字符,lower函数可以返回小写字符。

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注