[Tutor] implementing rot 13 problems

Peter Otten __peter__ at web.de
Tue Mar 12 17:53:21 CET 2013


RJ Ewing wrote:

> Thank you all for the help. I really appreciated the suggestions. Some of
> the things you pointed out, I originally used, but started changing thing
> when it wasn't working. I got it to work, but if you could let me know if
> there is anything I should do to make this code more pythonesque that
> would be great.
> 
> def rot_text(self, s):
> ls = list(s)
> for position, char in enumerate(ls):
> if char.isupper() or char.islower():
> test = 'M' if char.isupper() else 'm'
> if char <= test:
> ls[position] = chr(ord(char) + 13)
> else:
> ls[position] = chr(ord(char) - 13)
> return "".join(ls)

If you are interested in a different perspective on the same problem have a 
look into the "this" module of your python distribution. You can find the 
location of that file on your system by typing

import this
print this.__file__.rstrip("co")

into the interactive interpreter. Be sure to read the text that is printed 
out before proceeding to read the module that produced it.



More information about the Tutor mailing list