"Paul Rubin" <http://[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> "falcon" <[EMAIL PROTECTED]> writes:
>> I forgot to add that I passing a tuple of functions to the reduce
>> function but apparently that is not allowed.  My guess was that a tuple
>> made up of individual (simple) functions might be easier to manipulate
>> programatically than a function which has to know the structure of a
>> list.
>
> Python really doesn't support this style all that well.  Try Haskell.
> See also the SICP book, which uses Scheme.
>
>> (My test code)
>> x=[('a',1),('a',1),('a',3),('b',1),('b',2),('c',2),('c',3),('c',4)]
>> reduce((lambda x,y: x+y,lambda x,y: x+y),x)
>
> I can't even tell what you're trying to do there.
I think that this is what he wants.
def zipfunc(fun):
    def runfun(*args):
        return tuple(x(*y) for x,y in zip(fun,zip(*args)))
    return runfun

Use this as:
x=[('a',1),('a',1),('a',3),('b',1),('b',2),('c',2),('c',3),('c',4)]
reduce(zipfunc((lambda x,y: x+y,lambda x,y: x+y)),x)
I think he wants the apply the first function in the tuple to the first 
element in every tuple, and likewise the second, third, etc. 


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to