how to insert random error in a programming

Joshua Landau joshua.landau.ws at gmail.com
Mon Oct 15 19:07:42 EDT 2012


On 15 October 2012 20:51, Chris Angelico <rosuav at gmail.com> wrote:

> On Tue, Oct 16, 2012 at 6:28 AM, Mark Lawrence <breamoreboy at yahoo.co.uk>
> wrote:
> > I like clearly written code like this
> >
> > "
> > d = {}
> > for c in (65, 97):
> >     for i in range(26):
> >         d[chr(i+c)] = chr((i+13) % 26 + c)
> >
> > print "".join([d.get(c, c) for c in s])
>
> Surely there's a shorter way to rot13 a piece of text? CODE GOLF!
>
> 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))
>
> And with superfluous spaces removed like that, it takes 0.02
> jiggawatts less power in DeLorean Python.
>



> print("".join(chr([[ł,(ł+21)%26+96],[ł%26+65]][64<ł<91][96<ł<123])for ł in
> map(ord,s)))


That was fun. Remember, Unicode has more characters, so you can fit more
code in less space.

<*Oh God, what have I done?!>*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20121016/1fd14cc1/attachment.html>


More information about the Python-list mailing list