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])

Grounds for second bullet:
       print '%smatch' % (not value and 'Not a ' or '')


Are you objecting to the use of logical operators as conditionals? The list comprehension? The anonymous function? The functional style in general?

The program looks pretty clear to me, aside from using logical operators instead of conditionals, but AFAIK there's no explicit conditional expression in Python so one doesn't have much choice when attempting to program in functional style.

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.

                --Levi

/*
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