Passing every element of a list as argument to a function

Prasad, Ramit ramit.prasad at jpmorgan.com
Tue Aug 9 16:11:58 EDT 2011


-----Original Message-----
From: python-list-bounces+ramit.prasad=jpmorgan.com at python.org [mailto:python-list-bounces+ramit.prasad=jpmorgan.com at python.org] On Behalf Of Antonio Vera
Sent: Tuesday, August 09, 2011 12:02 PM
To: python-list at python.org
Subject: Passing every element of a list as argument to a function

Hi!,
I have a very simple syntax question. I want to evaluate a library
function f receiving an arbitrary number of arguments (like
itertools.product), on the elements of a list l. This means that I
want to compute f(l[0],l[1],...,l[len(l)-1]).

Is there any operation "op" such that f(op(l)) will give the sequence
of elements of l as arguments to f?

Thanks for your time.
Best,
Antonio
-- 
http://mail.python.org/mailman/listinfo/python-list

op(*l) for a list (or positional arguments).

If you are trying to pass named keyword arguments then you must pass it a dictionary { 'keywordName' : 'value' }
Example:
>>>def F(name=None):
      pass
>>>F(**{'name':'boo'})


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  



More information about the Python-list mailing list