[EMAIL PROTECTED] wrote: > I just started messing with programming and started with Python. Part > of my first project deals with translating numerical values to letters. > I would like to be able to do the reverse as well, letters to numbers, > sort of a table for lookup and a table for reverse lookup. I thought > that a dictionary would be the structure to use- write it once and in a > second instance swap the keys for values and values for keys. However, > reversing a dictionary does not seem to be easily achieved. Am I using > the wrong data structure? >
There may be a better solution to your original problem (if you post more details Im sure there will be plenty of suggestions), but the following should reverse a dictionary.. >>> testdict = dict(a=1, b=2) >>> reversedict = dict( (value, key) for key, value in testdict.iteritems() ) Will McGugan -- http://www.willmcgugan.com "".join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in "jvyy*jvyyzpthtna^pbz") -- http://mail.python.org/mailman/listinfo/python-list