MathGroup Archive 2008

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

Search the Archive

Re: Replacing elements in a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90105] Re: [mg90092] Replacing elements in a list
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sun, 29 Jun 2008 05:34:55 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

pairs = {{1, 2}, {3, 4}, {1, {1, 2}}};

elem = Union[Flatten[pairs, 1]]

{1,2,3,4,{1,2}}

pairs /. {x_, y_List} :> 
  {x, Position[elem, y][[1, 1]]}

{{1, 2}, {3, 4}, {1, 5}}


Bob Hanlon

---- yedidel at gmail.com wrote: 
> Hello,
> 
> I have a list of pairs that looks like this:
> 
> {{1,2},{3,4},{1,{1,2}}}
> 
> Each pair element can be a pair by itself.
> 
> I have another list which lists all elements possible:
> {1,2,3,4,{1,2}}
> 
> Now I want to create a list of rules that will take the element list
> and give it a running number ({1,2} will be 5 in this example)
> 
> after that I want to apply those rules to the pair list BUT that will
> do it only from the second level down. This means that the final
> result should be:
> 
> {{1,2},{3,4},{1,5}}
> without the first pair {1,2} changing to 5 because it is a pair and
> not an element.
> 
> 



  • Prev by Date: Subscript Bug?
  • Next by Date: Re: Re: Problem with NMaximize
  • Previous by thread: Re: Replacing elements in a list
  • Next by thread: Re: Replacing elements in a list