[Tutor] print as columns [using apply()]

Michael P. Reilly arcege@speakeasy.net
Tue, 17 Jul 2001 17:55:47 -0400 (EDT)


Danny Yoo wrote
> The guilt is not really on apply(), but max() --- max() can't handle a
> single argument: it always assumes that it works with at least two:
> 
[snipped]
> 
> On the other hand, reduce() should work on this pathological example:
> 
> ###
> >>> reduce(max, map(len, ([1],)))
> 1
> ###
> 
> 
> I must remind myself to test my programs with small "boundary" cases, just
> to make sure nothing leaks out... *grin*

Actually, on this, I'm almost surprised.  I'd think that you would have
to add the trailing initial value to reduce.

>>> reduce(max, map(len, ([1],)), 0)

Interestingly, max((1,)) returns 1 (yikes).

  -Arcege

-- 
+----------------------------------+-----------------------------------+
| Michael P. Reilly                | arcege@speakeasy.net              |