题解 | #字符串加密# sorted()/zip()

字符串加密

https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3

几个重点函数: sorted(,key=key.index),dict(zip(l,tmp))
while True:
    try:
        key,code=input(),input()
        #排序后按原来索引顺序
        tmp=sorted(set(key),key=key.index)
        #考虑到加密内容有空格,所以加上
        l=list("abcdefghijklmnopqrstuvwxyz ")
        for i in l:
            if i not in tmp:
                tmp.append(i)

        #zip()打包 dict()转字典类型
        dic=dict(zip(l,tmp))
        res=""
        for i in code:
            res+=dic[i]
        print(res)
            
        
    except:
        break


华为机试(python3) 文章被收录于专栏

少壮不努力,老大勤刷题

全部评论

相关推荐

01-09 17:12
四川大学 Java
叁六玖:上次建行给我开25万,让我扣2办理
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务