[Tutor] Re: Long and Nasty List Comprehensions... for fun. (original) (raw)

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


israel uandmedance.com <israel 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 C=2*sqrt((float(Args['R']))*2-(9/16(float(Args['R'])-float(Args['D'])/2)2)) O=0 N=STD L=str(23/4*(float(Args['R'])-float(Args['D'])/2))+'- self.Begin.x';self.Begin.y;100;100(sin(self.PhiMiddle))*2; 100(cos(self.PhiMiddle))**2

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.

Yours,

Andrei



More information about the Tutor mailing list