[Tutor] Re: Long and Nasty List Comprehensions... for fun.

Andrei project5 at redrival.net
Thu Jul 15 08:51:14 CEST 2004

israel <at> uandmedance.com <israel <at> uandmedance.com> writes:

> I've recently cooked up a very long list comprehension (1027  
> characters!) out of sheer perversity that creates a simple html image  
> gallery script.

I think you've been cheating a bit :). Your entire script is around that size,
but that includes a LOT of HTML text and a bunch of chained methods, which are
outside the list comprehension. Now although that has obsfucational qualities, 
it doesn't increase the complexity of the list comprehension as such. The way to
make horrendous list comprehensions is to nest and nest and nest and preferably
mix in some lambdas and extremely short variable names :).

> I was wondering if any of you had any tips for improving this  
> monstrosity of mine.

You mean for making it even uglier? Add some CSS definitions, preferably
configurable ones (like background color, border style, etc.).

> I'd also be interested in seeing any of your absurdly long one liners.  
> I know I'm only an artist posing as a programmer, so I feel assured  
> there are other out there who are far more insane than me.

I must confess I've never written a one-liner that long. I've written two or
three-lined list comprehensions (2 or 3 levels deep), but the debugging and
maintenance gets so painful, I don't go around chaining them in chained methods
:). I saw at some point a site with some large obsfucated python code pieces,
but I can't find it now.

Actually, now I think about it, I did at some point abuse the facilities Python
offers quite badly, but in a different way. I wrote an application where this
was a valid (and useful!) command line (had to split it over several lines, but
the whole thing is actually a single line):

script.py R=5.125 S=19 E=2 D=0.5

I was almost literally putting a square peg in a round hole. The application
(with a more decent command line) drew a circle with a polygon inside it and
with the modified command line, it drew two partly overlapping circles with two
polygons inside them, sharing a side which was drawn between the two points
where the two circles crossed.



More information about the Tutor mailing list