[英]How to convert a list of numbers to a list of letters, Python
python的新手,我正在嘗試編碼加密的消息
字母已被重寫如下:
cipher = [ "q", "a", "z", "w", "s", "x", "e", "d", "c", "r", "f", "v", "t", "g", "b", "y", "h", "n", "u", "j", "m", "i", "k", "o", "l", "p"]
idx = ord ("d") - ord ("a")
print(cipher[3])
輸出:w
input = str(input('Write Text: ')) #hello world used here
input = input.lower()
output = []
for character in input:
number = ord(character) - 97
output.append(number)
print(output)
輸出:
[7,4,11,11,14,-65,22,14,17,11,3]
不確定如何對應這兩個...
我試過了:
print(cipher[output])
返回TypeError:列表索引必須是整數或切片,而不是list
提前致謝
我認為您想要類似的東西:
deciphered = [cipher[i] if i > 0 else ' ' for i in output]
print(''.join(deciphered))
請注意i>0
位在那里處理空間,這導致number
-65 ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.