7-6 sdut-字母替换

方法一:使用list

judge = []
for i in range(26):
    judge.append( chr(65+25-i) )
# print(judge)
n= input()
n= [judge[ord(i)-65] if 'A'<=i<='Z' else i for i in n]
print(''.join(n))

方法2:使用map

judge = {}
for i in range(26):
    judge[chr(65+i)]=chr(65+25-i)
# print(judge)
n= input()
n= [judge[i] if 'A'<=i<='Z' else i for i in n]
print(''.join(n))
posted @ 2022-05-29 09:18  kingwzun  阅读(169)  评论(0编辑  收藏  举报