题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
利用 ^ 排除两个集合的重叠元素(可以得到得到两个列表的对称差)。
if __name__ == "__main__": s = input() text = input() pwd = [] for c in s: if c not in pwd: pwd.append(c) else: pass aph = [chr(i) for i in range(97, 123)] resd = list(set(pwd) ^ set(aph)) # use ^ to take out the repeating elements resd.sort() newPwd = pwd + resd for c in text: print(newPwd[aph.index(c)], end="")