MathGroup Archive 2006

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

Search the Archive

Replacing Numbers in a List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68230] Replacing Numbers in a List
  • From: Gregory Lypny <gregory.lypny at videotron.ca>
  • Date: Sun, 30 Jul 2006 04:47:53 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hello everyone,

I have a long list of integers called x, and I want to replace those  
that are members of list y with the number 222.

I did it this way with a Do loop.

y = {122, 211, 212, 221, 223, 232, 322};
Do[x = ReplacePart[x,222, Position[x, y[[i]]]],{i, Length@y} ]

Is this OK, or is there a more direct way?

Regards,

	Gregory


  • Prev by Date: Directories and Subdirectories
  • Next by Date: Import pdf into a Notebook
  • Previous by thread: Directories and Subdirectories
  • Next by thread: Re: Replacing Numbers in a List