how to insert random error in a programming

alex23 wuwei23 at gmail.com
Mon Oct 15 21:21:55 EDT 2012


On Oct 16, 5:52 am, Chris Angelico <ros... at 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]
    )
)



More information about the Python-list mailing list