MathGroup Archive 2006

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

Search the Archive

Re: List Help Needed

  • To: mathgroup at
  • Subject: [mg68867] Re: List Help Needed
  • From: albert <awnl at>
  • Date: Mon, 21 Aug 2006 06:33:23 -0400 (EDT)
  • References: <ecbo4l$r5j$>
  • Sender: owner-wri-mathgroup at

Nimrod wrote:

> What combination of Map, MapAt, ...
> will transform {{a,b},{c,d},...} to {{a,f[b]},{c,f[d]},...}
> Thanks in advance.
> Nimrod

I think you will need a pure function that handles the first and second
entry in the lists differently. This is a possibility with Map:

In[6]:= Map[{#[[1]],f[#[[2]]]}&,{{a, b}, {c, d}}]

Out[6]= {{a, f[b]}, {c, f[d]}}

For this case, Apply results in somewhat shorter code:

In[8]:= Apply[{#1,f[#2]}&,{{a, b}, {c, d}},{1}]

Out[8]= {{a, f[b]}, {c, f[d]}}

And using the short form of Apply[,{1}] it becomes even shorter:

In[9]:= {#1,f[#2]}& @@@ {{a, b}, {c, d}}

Out[9]= {{a, f[b]}, {c, f[d]}}



  • Prev by Date: Re: List Help Needed
  • Next by Date: RE: programming books / tutorials
  • Previous by thread: Re: Re: List Help Needed
  • Next by thread: Re: List Help Needed