MathGroup Archive 2006

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

Search the Archive

Re: Filtering same elements from two lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67958] Re: [mg67935] Filtering same elements from two lists
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Tue, 18 Jul 2006 05:50:53 -0400 (EDT)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

Not clear how you want all cases handled, but here is one method:

list1={{PLUS1,55,43},{PLUS2,555,83},{PLUS1,2,7}};

list2={{PLUS3,9,107},{PLUS1,77,99},{PLUS2,52,103}};

Join@@@Split[Sort[Join[list1,list2]],
      #1[[1]]==#2[[1]]&]//.{x_,y__,x_,z__}:>{x,y,z}

{{PLUS1,2,7,55,43,77,99},{PLUS2,52,103,555,83},{PLUS3,9,107}}


Bob Hanlon

---- LectorZ <lectorz at mail.ru> wrote: 
> Dear experts,
> 
> I do have to not ordered lists of the following type (same shape and
> length):
> 
> list1={{PLUS1, 55, 43}, {PLUS2, 555, 83}, {....},...}
> 
> list2={{..., ...,...}, {..., ...,...},{..., ...,...},{...,
> ...,...},{PLUS1,77, 99}, {..., ...,...},{PLUS2, 52,103}, {....}}
> 
> I have to filter the same records according to the 1st element of each
> sublist and make a new list with the joint numbers from both lists.
> 
> The result in this case should be:
> 
> resultlist={{PLUS1, 55, 43, 77, 99}, {PLUS2, 555, 83, 52,103}, {....}}
> 
> Thanks,
> 
> LZ
> 


  • Prev by Date: Re: NDSolve Problems
  • Next by Date: Re: Filtering same elements from two lists
  • Previous by thread: Re: Filtering same elements from two lists
  • Next by thread: Re: Filtering same elements from two lists