python学习之pythonchallenge

    最近学习Python,看到大家推荐的一些带有闯关和游戏性质的Python学习网站,其中就包括pythonchallenge。

   于是尝试着记录下来自己的一步步学习的过程,把相关的代码汇总和记录下来。下面是我个人尝试的代码:

ref = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']


def decode(message):
    List = list(message)
    mseg = ""
    for ch in List:
        if ch in ref:
            #print ref.index(ch)
            mseg += ref[(ref.index(ch)+2)%26]
        else:
            mseg += ch
    return mseg
message = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."

mesg = decode(message)

print str(mesg)

本关推荐使用

string.maketrans用来建立一个字符的映射表,结合字符的方法translate做非常方便.
下面是translate的解释:
translate(...)
    S.translate(table [,deletechars]) -> string

    Return a copy of the string S, where all characters occurring
    in the optional argument deletechars are removed, and the
    remaining characters have been mapped through the given
    translation table, which must be a string of length 256 or None.
    If the table argument is None, no translation is applied and
    the operation simply removes the characters in deletechars

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值