MathGroup Archive 2006

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

Search the Archive

Re: List Help Needed


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]}}

hth,

albert


  • 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