Changing numbers into characters using dictionaries

Danny dannybuck1 at gmail.com
Thu Jan 26 15:35:26 EST 2006


Hello again,

I am now trying to make something to change some "encrypted" text into 
some plain text, here is the code I have so far:

text = '@7704 at 7002@7075 at 7704' // some text
num = '213654' // Number
s1 = '700'
s2 = '770'
s4 = '707' // it adds these later on.
t = text.split('@') // splits the digits/blocks apart from each other
a = {s2+num[3]:"l", s1+num[0]:"a", s4+num[5]:"w"}

something = 1
while True:
     var = str(a[t[something]])
     print var,
// I want it to change "@7704 at 7002@7075 at 7704" into "lawl"

I get the error:
Traceback (most recent call last):
   File "C:/Documents and Settings/Danny/My 
Documents/python/changetext.py", line 9, in ?
     var = str(a[t[something]])
KeyError: '7704'

I've explained what is needed to happen in the comments. Also, if any of 
you can think of a better way to do this can you possibly tell me this? 
Thanks.



More information about the Python-list mailing list