How do I let a function accept a variable number of lists:

Alex Martelli aleaxit at yahoo.com
Wed May 30 02:36:49 EDT 2001


"scott" <smarsh at hotmail.com> wrote in message
news:3B14416B.22B3509B at hotmail.com...
    ...
> The problem is this line:
> x = stats.F_oneway(li[0], li[1])
>
> I've just set it to accept the first two lists.
> The docstring for lF_oneway includes:
> "Usage:   F_oneway(*lists)   where *lists is any number of lists, one
> per treatment group"
>
> Question:
> How do I automatically pass the correct number of lists to
> stats.F_oneway()?

That's exactly what the star-syntax does in the call, in
Python 2.


> If I could turn the list of lists into a series of lists i.e:
> li = [[1, 2], [3, 4], [5,6]] --> li = [1,2], [3,4], [5,6]]
> then I could presumably just pass li.

Right.  You call:
    x = stats.F_oneway(*li)
(note the asterisk) and that is just about what happens.


Alex






More information about the Python-list mailing list