Re: Q: efficient list operation wanted

*To*: mathgroup at smc.vnet.net*Subject*: [mg14004] Re: [mg13973] Q: efficient list operation wanted*From*: BobHanlon at aol.com*Date*: Sat, 12 Sep 1998 16:59:25 -0400*Sender*: owner-wri-mathgroup at wolfram.com

My original response was unnecessarily complex. This simpler form also works: n=0; L1 /. 3 :> (n++; L2[[n]]) Bob Hanlon _______________ L1 = {1, 2, 3, 4, 5, 3, 7, 2, 3, 9}; L2 = {a, b, c}; n=0; L1 /. (x_/;x==3) :> (n++; L2[[n]]) {1,2,a,4,5,b,7,2,c,9} Bob Hanlon In a message dated 9/11/98 7:54:56 PM, k.duellmann at uni-mannheim.deXXX wrote: >I am looking for an efficient solution of the following problem: > >Given two lists L1 = {1,2,3,4,5,3,7,2,3,9} and L2 = {a, b, c} > >I want to replace all numbers 3 in L1 by the elements of L2 >successively, >that is the first 3 by a, the second 3 by b and the third 3 by c. That >is I want to get the following modified L1-list: {1,2,a,4,5,b,7,2,c,9}. > >Replace[] unfortunately replaces elements with a single element only. Is >there a chance to avoid hideous Do-Loops? > >Any hints are appreciated!