Passing every element of a list as argument to a function

Discussion in 'Python' started by Antonio Vera, Aug 9, 2011.

  1. Antonio Vera

    Antonio Vera Guest

    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
     
    Antonio Vera, Aug 9, 2011
    #1
    1. Advertising

  2. On Tue, Aug 9, 2011 at 6:02 PM, Antonio Vera <> 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
     
    Chris Angelico, Aug 9, 2011
    #2
    1. Advertising

  3. -----Original Message-----
    From: python-list-bounces+ramit.prasad= [mailto:python-list-bounces+ramit.prasad=] On Behalf Of Antonio Vera
    Sent: Tuesday, August 09, 2011 12:02 PM
    To:
    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.
     
    Prasad, Ramit, Aug 9, 2011
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Kial
    Replies:
    1
    Views:
    700
    Eric Enright
    Nov 15, 2004
  2. Reckoner
    Replies:
    11
    Views:
    726
    Steven D'Aprano
    Jan 19, 2009
  3. AikidoGuy
    Replies:
    11
    Views:
    584
    Seebs
    Nov 21, 2011
  4. Tony
    Replies:
    4
    Views:
    116
    Tore Aursand
    Feb 24, 2004
  5. User1014
    Replies:
    1
    Views:
    198
    Richard Cornford
    Nov 30, 2006
Loading...

Share This Page