from __future__ import with_statement import string def trans(s): replace_table = { 'o': '0', 'i': '1', 'z': '2', 's': '5', 't': '7', 'g': '6', } for key, value in replace_table.iteritems(): s = s.replace(key, value) return s with open('/usr/share/dict/words') as f: for word in f: word = word.strip() newword = trans(word.lower()) if all(c in string.hexdigits for c in newword): print '%s: Ox%s' % (word, newword)