Passing every element of a list as argument to a function

A

Antonio Vera

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
 
C

Chris Angelico

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
 
P

Prasad, Ramit

-----Original Message-----
From: [email protected] [mailto:p[email protected]] On Behalf Of Antonio Vera
Sent: Tuesday, August 09, 2011 12:02 PM
To: (e-mail address 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?

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:


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top