Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pass list items as arguments to method

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])

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Any pointers would be appreciated.

>Solution :

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])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading