On Fri, Nov 03, 2006 at 11:32:38PM -0700, Dan Stovall wrote: > On 11/3/06, Levi Pearson <[EMAIL PROTECTED]> wrote: > >On Nov 3, 2006, at 4:30 PM, Andrew McNabb wrote: > > > >> I'm a big fan of Python, but this example made me want to cry. > >> > >> Grounds for first bullet: > >>> value = reduce(lambda x,y: 0 < abs(x-y) <= len(nums) and y or > >>> None, [int(item) for item in nums]) > > Well, I had a few reasons for doing this. I have read that map, > reduce, and list comprehesions are much faster and more efficient in > python because they are implemented in the underlying C code, but for > and while loops are not. I have been searching for the reference for > this but I can't find it.
Do the reduce, but define the function above. Maybe even use some of those newfangled conditionals like "if" and "else" statements in your function. > I also kind of wanted to show that python can be just as confusing and > ridiculous as some of the perl examples. I basically was going for > the best runtime, and smallest footprint as possible. Were I coding > this to be maintained it would have been completely different. Sure, you can make Python ugly. I admit it. But you have to go really far out of your way. "I want an 'if', but I don't want it to be readable. I wonder if I could do something goofy with the binary operators." You know you're a bad person when you're doing it. :) > >> Grounds for second bullet: > >>> print '%smatch' % (not value and 'Not a ' or '') > > This is bad I admit. I don't know why I coded it up this way at all. > I have no excuse, complete brain fart. As long as you aren't proud of it. :) > I agree, but I wanted to use the anonymous function since, again, it > is supposed to be faster and more efficient. How would an anonymous function be faster than a properly named one? -- Andrew McNabb http://www.mcnabbs.org/andrew/ PGP Fingerprint: 8A17 B57C 6879 1863 DE55 8012 AB4D 6098 8826 6868 /* PLUG: http://plug.org, #utah on irc.freenode.net Unsubscribe: http://plug.org/mailman/options/plug Don't fear the penguin. */