On Oct 16, 5:52 am, Chris Angelico <ros...@gmail.com> wrote: > Surely there's a shorter way to rot13 a piece of text? CODE GOLF!
In Python2: "a piece of string".encode('rot13') :) > At very least, a single cryptic expression in place of your nice clear > loops MUST be an improvement. > > d = dict((chr(i+c),chr((i+13)%26+c))for i in range(26)for c in(65,97)) Do I get points for explicitness? import string as s print "a piece of text".translate( s.maketrans( s.letters, s.letters[:26][13:]+s.letters[:26][:13]+s.letters[26:] [13:]+s.letters[26:][:13] ) ) -- http://mail.python.org/mailman/listinfo/python-list