-3

我有两个清单:

chars = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];

cipher = ["AA","AB","AC","AD","AE","AF","BA","BB","BC","BD","BE","BF","CA","CB","CC","CD","CE","CF","DA","DB","DC","DD","DE","DF","EA","EB","EC","ED","EE","EF","FA","FB","FC","FD","FE","FF"];

我想要这样,如果用户输入一行文本,它将字符中的文本与密码进行比较,例如,字符的第五个元素(“4”)对应于密码中的第五个元素(“AE” ),然后打印出来。如何做到这一点?

4

1 回答 1

6

我想你想要一本字典(另一个链接):

d = dict(zip(chars,cipher))

然后,要从角色中获取密码,您可以:

print d[whatever_char]  #prints the cipher associated with that character
于 2013-01-11T18:01:48.613 回答