MathGroup Archive 2006

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

Search the Archive

Re: List Help Needed

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68867] Re: List Help Needed
  • From: albert <awnl at arcor.de>
  • Date: Mon, 21 Aug 2006 06:33:23 -0400 (EDT)
  • References: <ecbo4l$r5j$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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