MathGroup Archive 1998

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

Search the Archive

Re: Q: efficient list operation wanted

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13987] Re: [mg13973] Q: efficient list operation wanted
  • From: Jurgen Tischer <jtischer at col2.telecom.com.co>
  • Date: Sat, 12 Sep 1998 16:59:12 -0400
  • References: <199809111907.PAA23222@smc.vnet.net.>
  • Sender: owner-wri-mathgroup at wolfram.com

Hallo Klaus,
how do you like this one?

In[1]:= l1 = {1,2,3,4,5,3,7,2,3,9};

In[2]:= l2 = {a, b, c};

In[3]:= n=1;

In[4]:= l1/.{3:>l2[[n++]]}

Out[4]= {1,2,a,4,5,b,7,2,c,9}

Jurgen

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




  • Prev by Date: Re: Options to exit NDSOLVE?
  • Next by Date: Re: Q: efficient list operation wanted
  • Previous by thread: Q: efficient list operation wanted
  • Next by thread: Re:Q: efficient list operation wanted