MathGroup Archive 1998

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

Search the Archive

Re: Q: efficient list operation wanted


try
L1 = {1,2,3,4,5,3,7,2,3,9}
 and 
L2 = {a, b, c}

Fold[ReplacePart[#1,#2,First at Position[#1,3]] & ,L1, L2]

wouter.

*******************************

At 15:07 11-09-98 -0400, Klaus Duellmann 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!
>
>PS. Remove XXX from my e-mail-address
>
>K. Duellmann
>
>
Dr. Wouter L. J. MEEUSSEN
w.meeussen.vdmcc at vandemoortele.be
eu000949 at pophost.eunet.be



  • Prev by Date: Re: Q: efficient list operation wanted
  • Next by Date: Re: Q: efficient list operation wanted
  • Previous by thread: Re: Q: efficient list operation wanted
  • Next by thread: Re: Q: efficient list operation wanted