簡體   English   中英

當鍵與列表中的字符匹配時打印字典中的鍵

[英]Print keys from dictionary when key matches with character from list

`

dic = {
     'A': 'o78t6df', 'B': '8f6pifg', 'C': 'd8s64ag', 'D': '09h8u0q', 'E': 'u6sr4a7', 'F': 'x4tz86u', 'G': '86xrd6y', 'H': 'uiztxr6', 'I': 're56tex', 'J': 'ot76t6x', 
     'K': '8t97tc8', 'L': 'do7ztrd', 'M': 'p8t5s65', 'N': 'p8d6zrx', 'O': 'kzrxyrt', 'P': 'p86e7ea', 'Q': 'lutsd53', 'R': 'o785sde', 'S': 'olzsr53', 'T': 'wrp8z76', 
     'U': 'olutxcd', 'V': 'ut5aesq', 'W': 'nyvxu64', 'X': 't4w3qfs', 'Y': 'z532syd', 'Z': 'kzfxyt4', ' ': ' ', '1': 'i6rsweq', '2': 'uteas12', '3': 'p7g9txx', 
     '4': 'iz765s9', '5': 'ddd5tx1', '6': 'k7w4x49', '7': 'w33rr6y', '8': 'y54xsqw', '9': 'ol75sdy', '0': 'bbi75sa', '!': 'utdf55y', '?': 'uiw123x', '"': 'setuuwa', 
     '(': 'uzt5eys', ')': 'lutzcq1', '=': '6q245ss', '§': '1bc1121', '%': 'xyfvz45', '&': 'erw3646', '#': 'zutes34', '-': '35qw4z4', ',': 'q2543we', '/': 'q352s4e'
}

if choice_start=='e':
    print(Fore.GREEN + '► ')
    print(' ')
    print(Fore.GREEN + '⎯⎯⎯» Your Message «⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯')
    print(' ')
    message = input(Fore.RESET + '⌬  ')
    print(' ')
    print(Fore.GREEN + '⎯⎯⎯» Secret message «⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯')
    print(' ')
    message = message.upper()
    characters_list = []
    characters_list[:0] = message
    for i in characters_list:
        print(Fore.GREEN + dic[i])
    print(' ')
    print(Fore.GREEN + '⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯')
    time.sleep(50)

elif choice_start=='d':
    print(Fore.GREEN + '► Decyrpt')
    print(' ')
    print(Fore.GREEN + '⎯⎯⎯» Encrypted Message «⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯')
    print(' ')
    message = input(Fore.RESET + '⌬  ')
    print(' ')
    print(Fore.GREEN + '⎯⎯⎯» Decrypted message «⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯')
    print(' ')


dict = {'a': 'a1', 'b': 'b1'}
list = [a1]

...

print('key from a1 is: (key x)')

`

我想解密消息,但不知道如何解密。 (我是初學者!)

因此,當 se 用戶輸入 o78t6df 時,代碼會打印出 A。但我需要整個句子。

有人能幫我嗎?

你的描述令人困惑。 但似乎你正在尋找這樣的東西。

my_dict = {'a': 'a1', 'b': 'b1'}
my_list = ['a1']
for item in my_dict:
    if my_list[0] == my_dict[item]:
        print('key from a1 is: {}'.format(item))

如果這是你的目標那么結束。 如果不通過更多解釋編輯您的問題。

編輯:如果您的列表包含更多內容, for使用另一個!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM