This question already has an answer here:

The minimal working example of my problem is as follows:

l = {1, 2, 3, 4}
f[a_, b_, c_, d_] = a + b + c + d

Now, I'd like to evaluate


, but with a syntax like f[Unwrap[l]].

I don't have access to the code of 'f', and I can't simply change the way it is defined to accept a list

Basically, I am missing the functionality present in Python with the *,

def f(a,b,c,d):
    return a+b+c+d
print f(*l)

marked as duplicate by rm -rf Jul 8 '13 at 18:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ list = {1, 2, 3, 4}; f[a_, b_, c_, d_] = a + b + c + d; f[Sequence @@ list] ? $\endgroup$ – Dr. belisarius Jul 8 '13 at 18:36
  • $\begingroup$ f@@l does the trick ;) (python pah!) $\endgroup$ – Stefan Jul 8 '13 at 18:37
  • $\begingroup$ Related question. $\endgroup$ – Leonid Shifrin Jul 8 '13 at 18:49
  • $\begingroup$ Sorry, this had already been asked. $\endgroup$ – flebool Jul 8 '13 at 19:00
  • $\begingroup$ @rm-fr If this link should be considered canonical Q&A maybe You will put there Operate based answer. $\endgroup$ – Kuba Jul 8 '13 at 19:15

There are two ways of doing this that are mostly equivalent. First,

f[ Sequence @@ l ]
(* 10 *)

But, the use of Sequence is to many characters, in my opinion, and there is a better way. Essentially, the notation @@ is shorthand for the function Apply which replaces the Head of an expression with another head. In the prior case, Sequence replaced the head List which was then passed into f. But, this can be used directly,

f @@ l
(* 10 *)

which replaces the head List with f.


and the third one (thanks to rm -rf)

l = {a, b, c, s};
Operate[f &, l]
f[a, b, c, s]

but in such simple case f@@l is what I use.


Not the answer you're looking for? Browse other questions tagged or ask your own question.