a python puzzle

David Brown david at no.westcontrol.spam.com
Fri Sep 27 08:21:51 EDT 2002


I'm not too interested in the crypogram puzzle, but your solution here has
just given me a solution to something that has been bugging me for some
time - finding an easy way to convert a list of characters into a string:

>>> a = "Hello"
>>> b = [x for x in a]
>>> b
['H', 'e', 'l', 'l', 'o']
>>> "".join(b)
'Hello'
>>>

Thanks !

>
> def decrypt(yourstring):
>     dedict = {'F': 'S', 'I': 'C', 'H': 'I', 'a': 't', 'c': 'f', 'b': 'v',
'e': 'n',
>     'd': 'o', 'f': 's', 'i': 'c', 'h': 'i', 'k': 'p', 'j': 'h', 'm': 'l',
>     'l': 'j', 'o': 'm', 'q': 'u', 'p': 'w', 's': 'b', 'u': 'z', 't': 'd',
>     'w': 'y', 'v': 'x', 'y': 'e', 'x': 'a', 'z': 'g', 'g': 'k'}
>     return "".join([dedict.get(i,i) for i in yourstring])
>






More information about the Python-list mailing list