Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: To apply a function to a List

  • To: mathgroup at
  • Subject: [mg65638] Re: [mg65597] To apply a function to a List
  • From: "David Park" <djmp at>
  • Date: Tue, 11 Apr 2006 04:04:52 -0400 (EDT)
  • Sender: owner-wri-mathgroup at



testlist = Range[5]
{1, 2, 3, 4, 5}

Then you can either Map f onto the list (see Map in Help)

f /@ testlist
{f[1], f[2], f[3], f[4], f[5]}

or you can set the Attributes of f to Listable (see Attributes in Help) Do
it before defining f if f has a definition.

Attributes[f] = Listable;

f[1], f[2], f[3], f[4], f[5]}

f[x_] := x^2
{1, 4, 9, 16, 25}

Here is another function, g, defined as a pure function (look up Function in
Help). It takes the square and subtracts 1.

g = #^2 - 1 &;

g /@ testlist
{0, 3, 8, 15, 24}

In general, you will find the 'functional' programming constructs very

David Park
djmp at

From: Francisco Javier [mailto:pacoga at]
To: mathgroup at

Dear all,

Let f, l be a function and a list respectively. How can we do

Table[f[list[[n]]],{n,1, Length[list]}]

in another way?


Francisco Javier García Capitán

  • Prev by Date: Re: Help with Identities
  • Next by Date: Re: For Loop problem
  • Previous by thread: Re: To apply a function to a List
  • Next by thread: Re: To apply a function to a List