MathGroup Archive 2010

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

Search the Archive

Re: need something like ReplaceAllIndexed[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108481] Re: need something like ReplaceAllIndexed[]
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Fri, 19 Mar 2010 06:45:31 -0500 (EST)
  • References: <hnva5p$88b$1@smc.vnet.net>

Hi,
> 
> I have an expression like this:
> 
> b[ a[c], a[c], a[d]]
> 
> a list like this:
> 
> {e,f,g}
> 
> I want to end up with
> 
> b[ a[e], a[f], a[g]]
> 
> I think of this as interleaving a list into an expression, but all my
> tries with ./,.//,MapIndexed[],MapAt[], Partition[Riffle[]] have come
> to no avail.
> 
> Any help on this is greatly appreciated.
> 
> Roger Williams
> Franklin Laboratory
> http://www.youtube.com/congruentlight

one way with MapIndexed:

expr = b[a[c], a[c], a[d]]

list = {e, f, g}

MapIndexed[Head[#1][list[[#2[[1]]]]] &, expr]

hth,

albert


  • Prev by Date: Re: Import html
  • Next by Date: Re: Sorting nested lists
  • Previous by thread: Re: need something like ReplaceAllIndexed[]
  • Next by thread: Re: need something like ReplaceAllIndexed[]