Velocity Reviews > Passing every element of a list as argument to a function

# Passing every element of a list as argument to a function

Antonio Vera
Guest
Posts: n/a

 08-09-2011
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?

Best,
Antonio

Chris Angelico
Guest
Posts: n/a

 08-09-2011
On Tue, Aug 9, 2011 at 6:02 PM, Antonio Vera <(E-Mail Removed)> wrote:
> 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?

Yep!

f(*l)

Chris Angelico

Guest
Posts: n/a

 08-09-2011
-----Original Message-----
Sent: Tuesday, August 09, 2011 12:02 PM
To: http://www.velocityreviews.com/forums/(E-Mail Removed)
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?

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.