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

I'm trying out the (very nice) stats module from
http://www.*-*-*.com/
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.



Sun, 16 Nov 2003 08:40:22 GMT  
 How do I let a function accept a variable number of lists:

    ...

Quote:
> 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.

Quote:
> 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



Sun, 16 Nov 2003 14:36:49 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. passing functions with variable number of arguments as procedure arguments

2. initializing list with number of elements given by a variable

3. function with variable number of arguments

4. Functions with variable number of commands

5. Pickler that handles modules, functions, and builtin functions -- done

6. C functions with variable parm lists

7. How to get the list of imported variables/functions

8. Dolphin 4.01 will not accept my serial number

9. File name no accept begin with number

10. Registration form does not accept serial number.

11. accept number

12. formula node does not accept complex variables

 

 
Powered by phpBB® Forum Software