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.  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.

> 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.

The ugly part to me is where it relies on generating a type error to
exit the reduce function upon failure.  My Lisp version did roughly
the same thing, but explicitly threw an exception instead of relying
on a runtime type error.

I agree, but I wanted to use the anonymous function since, again, it
is supposed to be faster and more efficient.  I could have defined my
own function that explicity raised an error and called it in the
reduce, but again, I wasn't trying to write maintainable code, just
something that would run as fast and efficiently as possible.  For
this example though, it probably doesn't make any difference at all.


Dan

--
I swear Power Point is going to be the downfall of higher education in
western society.

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to