From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7390c574595380ae X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-01-02 09:10:17 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!213-196-68-75.hosts.streamgate.DE!not-for-mail From: Gerhard =?iso-8859-15?Q?H=E4ring?= Newsgroups: comp.lang.ada Subject: [OT] Obfuscated Python Date: 2 Jan 2002 17:10:14 GMT Organization: Ye 'Ol Disorganized NNTPCache groupie Message-ID: References: <20020101220112.4bd5727d.matthew@starbreaker.net> <20020101225822.6d51fdf8.matthew@starbreaker.net> NNTP-Posting-Host: 213-196-68-75.hosts.streamgate.de (213.196.68.75) X-Trace: fu-berlin.de 1009991414 24475887 213.196.68.75 (16 [124666]) User-Agent: slrn/0.9.7.3 (Linux) Cache-Post-Path: gargamel.hqd-internal!gerhard@lilith.hqd-internal X-Cache: nntpcache 2.4.0b2 (see http://www.nntpcache.org/) Xref: archiver1.google.com comp.lang.ada:18453 Date: 2002-01-02T17:10:14+00:00 List-Id: Ted Dennison schrieb im Artikel : > In article , 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 bigfoot 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')))