MathGroup Archive 2008

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

Search the Archive

Re: Clever way to manipulate lists

  • To: mathgroup at smc.vnet.net
  • Subject: [mg94389] Re: Clever way to manipulate lists
  • From: dh <dh at metrohm.com>
  • Date: Thu, 11 Dec 2008 07:27:43 -0500 (EST)
  • References: <ghqjve$14i$1@smc.vnet.net>


Hi,

if I understand correctly, you have two list of tuples. The first 

tupel-element in both lists come from the same set. The second tuple 

element does not matter. You want all elements of the first list that 

have the first tuple element in common with an element from the second list.

This can be done with Intersection:

Intersection[list1,list2,SameTest->#1[[1]]===#2[[1]]]

Note that list1 and list should already be ordered the way mathematica 

likes it. Otherwise mathematica will reaoder the result. Further, the 

above works for numerical lists.

hope this helps, Daniel





guerom00 wrote:

> Hi everyone,

> 

> I'm still struggling through lists manipulation. I'll take a concrete

> example to illustrate my point.

> Let's say I have a first list, say coordinates on a regular grid :

> 

> list1={{x1,y1},{x2,y2},{x3,y3}...{xN,yN}}

> 

> This obviously has a Length of N. Now, let's say I have a second list.

> In this one, there are fewer than N elements, some points are

> missing... Let's say it misses a point at x2 :

> 

> list2 ={{x1,z1},{x3,z3},{x4,z4}...{xN,zN}}

> 

> Now, since those two lists are not of the same length, I cannot add

> them, substract them or something. But list2 is included in list1 (in

> the sense of set theory). Now, what I want to do is, in this example,

> remove the point {x2,y2} from list1 and then the two list will have

> the same length and I'll be able to manipulate them as I want.

> Right now, I do that with For loops (detect elements which are in

> list1 and not in list2 and delete them, etc...) and that works but it

> is not elegant.

> I'm looking for a concise, elegant way to do that if somebody sees

> what I mean...

> 

> Thanks in advance :)

> 




  • Prev by Date: Re: Clever way to manipulate lists
  • Next by Date: Re: Small question about Filling between two functions in a determined interval
  • Previous by thread: Re: Clever way to manipulate lists
  • Next by thread: Re: Clever way to manipulate lists