-1

Assuming i have a method definition like this do_stuff(*arg).

I have a list of values, ['a','b',...]. How best can i pass the values of this list as individual arguments to the do_stuff method as do_stuff('a','b',...) ?

I've unsuccessfully tried using list comprehension - do_stuff([str(value) for value in some_list])

I am hoping i don't have to change do_stuff() to accept a list

Any pointers would be appreciated.

dev
  • 382
  • 1
  • 3
  • 17

2 Answers2

1

It's the same syntax, with the *:

do_stuff(*['a','b','c'])
Tim Roberts
  • 48,973
  • 4
  • 21
  • 30
1

You can pass them using the "*" operator. So an example would be like this:

def multiplyfouritems(a,b,c,d):
    return a*b*c*d

multiplyfouritems(*[1,2,3,4])