NameError: name 'maketrans' is not defined, pythonchallenge
Guilherme Polo
ggpolo at gmail.com
Tue Jun 24 14:50:37 EDT 2008
On Tue, Jun 24, 2008 at 3:11 PM, cirfu <circularfunc at yahoo.se> wrote:
> from string import maketrans
>
> ok but how can i write:
> pattern = maketrans('A-XY-Za-xy-z', 'C-ZA-Bc-za-b')
> pattern = maketrans('A-Za-z', 'C-Bc-b')
> none works....
maketrans doesn't work like that, you would need something like this:
sfrom = string.uppercase + string.lowercase
sto = string.uppercase[2:] + string.uppercase[:2] +
string.lowercase[2:] + string.lowercase[:2]
table = string.maketrans(sfrom, sto)
print string.translate(phrase, table)
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
-- Guilherme H. Polo Goncalves
More information about the Python-list
mailing list