while True:
    try:
        key_word = input()
        string_in = input()
        new_key=[]
        letterlst = []
        string_out =''
        for i in range(26):
            letterlst.append(chr((ord("a")+i)))
        for word in key_word:
            if word not in new_key:
                new_key.append(word)
        for letter in new_key:
            letterlst.remove(letter)
        new_key.extend(letterlst)
        for str in string_in:
            if str.isalpha():
                index= ord(str)-97
                string_out+=new_key[index]
            else:
                string_out+=str
        print(string_out)
        
    except:
        break

重点几个python function:

  1. ord("a") 根据给定的character 返回Unicode code (ord("a")=97)
  2. chr() 参数是一个范围在255内的整数,返回对应的字符 (chr()和ord()可以看作互逆的函数)