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

scott smarsh at hotmail.com
Tue May 29 20:40:22 EDT 2001


I'm trying out the (very nice) stats module from
http://www.nmr.mgh.harvard.edu/Neural_Systems_Group/gary/python.html 
I'm using Win NT4 and  Python 2.0:

----------------------------------------
import pstat, stats


def DoAnova():
    ''' A command line interface to calculate one-way ANOVA. '''
    numPoints = input('How many data points in each group? ')
    numGroups = input('How many groups are there (2 minimum)? ')
    li = [0]
    for i in range(numGroups - 1):
        li.append(0)
    for i in range(numGroups):
        li[i] = [0]*numPoints
    for group in range(numGroups):
        for point in range(numPoints):
            li[group][point] = input('Enter a data point: ')
    print li
                          
    x = stats.F_oneway(li[0], li[1])
    print x

DoAnova()
---------------------------------------

Problem:
The above works properly for 2 lists ONLY. e.g.: [1,2], [3,4]
It returns:
[[1, 2], [3, 4]]
(8.0, 0.10557280898846583)  

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()?

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.  

Thanks in advance.



More information about the Python-list mailing list