Re: need something like ReplaceAllIndexed[]
- To: mathgroup at smc.vnet.net
- Subject: [mg108484] Re: need something like ReplaceAllIndexed[]
- From: Yves Klett <yves.klett at googlemail.com>
- Date: Fri, 19 Mar 2010 06:46:04 -0500 (EST)
- References: <hnva5p$88b$1@smc.vnet.net>
Hi,
what about:
target=b[a[c],a[c],a[d]];
replace={e,f,g};
ReplacePart[target,MapIndexed[{#2[[1]],1}->#&,replace]]
b[a[e],a[f],a[g]]
ReplacePart may possibly be slow for large alterations (see e.g.
http://www.mathprogramming-intro.org/book/node288.html)
Regards,
Yves
Am 19.03.2010 08:47, schrieb divisor:
> Hello mathGroup:
>
> 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
>