Python列表比较&打印

时间:2013-01-11 18:00:29

标签: python list

我有两个清单:

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”),打印出来。如何实现这一目标?

1 个答案:

答案 0 :(得分:6)

我想你想要一个dictionary(另一个link):

d = dict(zip(chars,cipher))

然后,要从角色获得密码,你会这样做:

print d[whatever_char]  #prints the cipher associated with that character