Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Q: efficient list operation wanted

  • To: mathgroup at
  • Subject: [mg13987] Re: [mg13973] Q: efficient list operation wanted
  • From: Jurgen Tischer <jtischer at>
  • Date: Sat, 12 Sep 1998 16:59:12 -0400
  • References: <>
  • Sender: owner-wri-mathgroup at

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}


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