comp.lang.ada
 help / color / mirror / Atom feed
From: "Gerhard Häring" <gerhard@bigfoot.de>
Subject: [OT] Obfuscated Python
Date: 2 Jan 2002 17:10:14 GMT
Date: 2002-01-02T17:10:14+00:00	[thread overview]
Message-ID: <slrna36fni.142.gerhard@lilith.hqd-internal> (raw)
In-Reply-To: xkFY7.553$cD4.485@www.newsranger.com

Ted Dennison schrieb im Artikel <xkFY7.553$cD4.485@www.newsranger.com>:
>  In article <slrna351vj.5m2.gerhard@gargamel.hqd-internal>, Gerhard
> =?iso-8859-15?Q?H=E4ring?= says...
> >
> >Matthew Graybosch wrote:
> >>  Hey, the last line in your sig is LISP code, isn't it?
> >
> >Close, but not quite. Abusing Python's functional features:
> >
> >reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))
>  
>  That makes sense. It starts off looking like Lisp that might be readable given
>  good knolwedge of the language and a bit more white space, but it ends up
>  looking like line noise.

If one really wants to write this as a one-liner in Python, it's
probably best written using Haskell-like list comprehensions:

''.join([chr(ord(x)^42) for x in tuple('zS^BED\nXEIAY\x0b')])

which is pretty idiomatic Python.

I'll cite Fredrik Lundh's insights on (over)using lambdas:

here's the eff-bot's favourite lambda refactoring rule: 
1) write a lambda function
2) write a comment explaining what the heck that lambda does
3) study the comment for a while, and think of a name that captures
   the essence of the comment
4) convert the lambda to a def statement, using that name
5) remove the comment

-- Fredrik Lundh, 01 Apr 2001

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))



  reply	other threads:[~2002-01-02 17:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-02  3:01 Need manual for GNAT on FreeBSD 4.4-Release on i386 (AMD Athlon) Matthew Graybosch
2002-01-02  3:27 ` Gerhard Häring
2002-01-02  3:31 ` Gerhard Häring
2002-01-02  3:58   ` Matthew Graybosch
2002-01-02  4:10     ` Gerhard Häring
2002-01-02 15:05       ` Ted Dennison
2002-01-02 17:10         ` Gerhard Häring [this message]
2002-01-02 23:57       ` Matthew Graybosch
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox