0
所以我正在做一個項目,我試圖猜測已經被改變的消息的關鍵。郵件從字符轉換爲ASCII碼,然後將密鑰添加到ASCII碼中,然後轉換回字符。我正在努力弄清楚如何得到一個if語句,如果消息和一個單詞庫之間存在交集,它將返回一些東西。它永遠不會返回正確的東西。思考?python internsection if語句
import re
from list_maker import *
message = input("what is your code? ")
list_broken = [ord(i) for i in message]
key = 27
num = 26
for l in list_broken:
key -= 1
list_decoded = [chr(i - key) for i in list_broken]
final = ''.join(list_decoded)
word_list = re.sub("[^\w]", " ", final).split()
S1 = set(word_list)
S2 = set(set_of_words)
i = 0
for e in S1:
if e in S2:
break
print(word_list)
print(key)
在集,交集是'&'操作。 '如果S1&S2:...' – khelwood
或者你可以使用'set.intersection(s1,s2)' – alpert