newbie: working iwth list of tuples
john at baumanfamily.com
Sun Jan 29 09:07:39 CET 2006
"Paul Rubin" <http://phr.cx@NOSPAM.invalid> wrote in message
news:7xoe1vtu68.fsf at ruckus.brouhaha.com...
> "falcon" <shahbazc at gmail.com> 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
> Python really doesn't support this style all that well. Try Haskell.
> See also the SICP book, which uses Scheme.
>> (My test code)
>> 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.
return tuple(x(*y) for x,y in zip(fun,zip(*args)))
Use this as:
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.
More information about the Python-list