这是我的代码:
lijst = ['H', 'e', 'l', 'l', 'o', 'h', 'o', 'w', 'a', 'r', 'e','y','o','u', 'i', 's', 'e', 'v', 'e', 'r', 'y', 't', 'h', 'i', 'n', 'g', 'f', 'i', 'n', 'e']
aa = ['a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','a','j','j','j','j','j','j','j','j','j','j','j','j','j','j','j','j','j','j','j','j','j','j','j','j','j','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d','k','k','k','k','k','k','k','k','k','k','k','k','k','k','k','k','k','k','k','k','k','k','k','k','k','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','s','i','i','i','i','i','i','i','i','i','i','i','i','i','i','i','i','i','i','i','i','i','i','i','i','i','r','r','r','r','r','r','r','r','r','r','r','r','r','r','r','r','r','r','r','r','r','r','r','r','r','u','u','u','u','u','u','u','u','u','u','u','u','u','u','u','u','u','u','u','u','u','u','u','u','u','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','x','b','b','b','b','b','b','b','b','b','b','b','b','b','b','b','b','b','b','b','b','b','b','b','b','b','l','l','l','l','l','l','l','l','l','l','l','l','l','l','l','l','l','l','l','l','l','l','l','l','l','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','w','m','m','m','m','m','m','m','m','m','m','m','m','m','m','m','m','m','m','m','m','m','m','m','m','m','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','t','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','q','q','q','q','q','q','q','q','q','q','q','q','q','q','q','q','q','q','q','q','q','q','q','q','q','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','g','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','z','n','n','n','n','n','n','n','n','n','n','n','n','n','n','n','n','n','n','n','n','n','n','n','n','p','p','p','p','p','p','p','p','p','p','p','p','p','p','p','p','p','p','p','p','p','p','p','p','p','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','f','f','f','f','f','f','f','f','f','f','f','f','f','f','f','f','f','f','f','f','f','f','f','f','f','f','v','v','v','v','v','v','v','v','v','v','v','v','v','v','v','v','v','v','v','v','v','v','v','v','v','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','o','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e','e']
for c in lijst:
i = i+1
lijst[i] = lijst[i].replace('a',aa[((i))*25%650])
lijst[i] = lijst[i].replace('b',aa[((i+1))*25%650])
lijst[i] = lijst[i].replace('c',aa[((i+2))*25%650])
lijst[i] = lijst[i].replace('d',aa[((i+3))*25%650])
lijst[i] = lijst[i].replace('e',aa[((i+4))*25%650])
lijst[i] = lijst[i].replace('f',aa[((i+5))*25%650])
lijst[i] = lijst[i].replace('g',aa[((i+6))*25%650])
lijst[i] = lijst[i].replace('h',aa[((i+7))*25%650])
lijst[i] = lijst[i].replace('i',aa[((i+8))*25%650])
lijst[i] = lijst[i].replace('j',aa[((i+9))*25%650])
lijst[i] = lijst[i].replace('k',aa[((i+10))*25%650])
lijst[i] = lijst[i].replace('l',aa[((i+11))*25%650])
lijst[i] = lijst[i].replace('m',aa[((i+12))*25%650])
lijst[i] = lijst[i].replace('n',aa[((i+13))*25%650])
lijst[i] = lijst[i].replace('o',aa[((i+14))*25%650])
lijst[i] = lijst[i].replace('p',aa[((i+15))*25%650])
lijst[i] = lijst[i].replace('q',aa[((i+16))*25%650])
lijst[i] = lijst[i].replace('r',aa[((i+17))*25%650])
lijst[i] = lijst[i].replace('s',aa[((i+18))*25%650])
lijst[i] = lijst[i].replace('t',aa[((i+19))*25%650])
lijst[i] = lijst[i].replace('u',aa[((i+20))*25%650])
lijst[i] = lijst[i].replace('v',aa[((i+21))*25%650])
lijst[i] = lijst[i].replace('w',aa[((i+22))*25%650])
lijst[i] = lijst[i].replace('x',aa[((i+23))*25%650])
lijst[i] = lijst[i].replace('y',aa[((i+24))*25%650])
我想要输出:
['H', 'a', 'a', 'i', 'k', 'j', 's', 'k', 'i', 'a', 'k', 'j', 's', 'a', 'b', 'd', 'l', 'c', 'h', 'a', 'e', 'p', 'd', 'd', 'i', 'v', 'e']
现在可以使用,但是我有一个250个字符的列表,有没有更Python的方法来做到这一点?我想要一个26个字符的列表(相同的列表,但每个字符仅一次)并且我想要相同的输出? 谢谢!
答案 0 :(得分:1)
You can create your aa list as such:
letters = ['a', 'j', 'd'] #The letters you want here
aa = []
for l in letters:
aa += [l]*number_of_times_letter_should_be_repeated
Your for loop can be refactored like:
for i, c in enumerate(lijst):
ascii = ord(c) - 97
if ascii < 0 or ascii > 24: # your code only goes to replacing y? otherwise put in 25.
continue
lijst[i] = aa[(i+ascii)*25%650]
the for loop without aa:
for i, c in enumerate(lijst):
ascii = ord(c) - 97
if ascii < 0 or ascii > 24: # your code only goes to replacing y? otherwise put in 25.
continue
letters_index = round((i+ascii+1)*25%650)/25 - 0.5) # Do check this because it isn't clear to me if this does what you are actually after.
lijst[i] = aa[letters_index]
答案 1 :(得分:-1)
编辑: 首先,您必须为所有替代词创建字典,如下所示:
subs = {'a':'@',
'b':'%',
'c':'*'
}
等
对于加密,请尝试以下操作:
def encrypt(text):
for c in text:
text.replace(c, subs[c])
return text
while True:
text = str(input('>'))
print(encrypt(text))