Code: Alles auswählen
In [53]: valid = 'abcäöü'
In [54]: valid.index(u'\xe4') # Ist ein ä.
---------------------------------------------------------------------------
<type 'exceptions.UnicodeDecodeError'> Traceback (most recent call last)
/home/bj/<ipython console> in <module>()
<type 'exceptions.UnicodeDecodeError'>: 'ascii' codec can't decode byte 0xc3 in position 3: ordinal not in range(128)
Weiteres Problem falls die Kodierung des Quelltextes nicht ein Byte pro Zeichen ist, also zum Beispiel UTF-8:
Code: Alles auswählen
In [68]: valid = string.ascii_letters + 'ÄÖÜäöü'
In [69]: zahl = 5
In [70]: [valid[(valid.index(ch) + zahl) % len(valid)] for ch in 'VXZ']
Out[70]: ['\xc3', '\xc3', '\xc3']