tree functions daily exercise: Table
Duncan Booth
duncan.booth at invalid.invalid
Wed Jun 22 04:41:03 EDT 2005
Xah Lee wrote:
> oops, another error. The example should be:
>
> Table(f,[1,2,1],[2,6,2]) returns
> [[f(1,2),f(1,4),f(1,6)],[f(2,2),f(2,4),f(2,6)]]
>
>> Wouldn't it be more sensible just to take the iterators directly as
>> arguments, so for this example you would do:
>>
>> Table(f, range(1,3), range(2,7,2))
>
> well yes... but this was emulation of Mathematica functions.
> (Disclaimer: Mathematica is a trademark of Wolfram Research Inc, who is
> not affliated with this project)
>
> What you suggested is a function called Outer in Mathematica. The Table
> function is in a sense multi-dimentional version of Range, so they
> share syntax form.
>
Ok, so, if I understand you, the definition of Table is just:
def Table(f, *lists):
return Outer(f,
*[range(start,end+1,step) for (start,end,step) in lists])
Is that about right?
More information about the Python-list
mailing list