1

I have a nested list called model and I want to use its items as the inputs of

scipy.stats.kruskal()     

That is, if my nested list has n=5 lists inside it, I want to obtain

scipy.stats.kruskal(model[0],model[1],model[2],model[3],model[4])

However n changes depending on the application, and sometimes, instead of 5, I may have 3 and etc.

My initial idea was

    s=''
    for i in range(n):
        a='model_errors[{}],'.format(i)
        s+=a
    s=s[:-1]
    scipy.stats.kruskal(eval(s))

However eval() returns the initial nested list, and not the terms separated with a comma. I've been trying many different things, but none of them were successful.

corsetti
  • 25
  • 3
  • 1
    `scipy.stats.kruskal(*model)` should do the trick. see https://stackoverflow.com/a/3394898/129600 – acushner Oct 14 '20 at 17:12

1 Answers1

1

You can use *, it can pass a list to the function, and ** for keyword arguments like dictionaries. So try scipy.stats.kruskal(*model)

Wasif
  • 14,755
  • 3
  • 14
  • 34