Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2010

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

Search the Archive

Re: Finding shared element in two lists

  • To: mathgroup at
  • Subject: [mg114089] Re: Finding shared element in two lists
  • From: Peter Breitfeld <phbrf at>
  • Date: Tue, 23 Nov 2010 05:59:36 -0500 (EST)
  • References: <icdoc5$6ho$>

Jason Ebaugh wrote:

> I am trying to write a function that would take two lists of increasing more
> precise location, and return the most specific level of geography that they
> share.
> myhouse={"Earth", "North America", "USA", "Illinois", "Champaign County",
> "Urbana"};
> friendshouse={"Earth", "North America", "USA", "Minnesota", "Ramsey County",
> "St. Paul"};
> In this case, the function should output USA.
> I could do this procedurally well enough. But I am really trying to get
> comfortable with functional programming.
> The above is just a more digestible version of what I am really trying to
> do. I want to find the lowest level of taxonomy that two species share.
> Ex:
> aphid={"Insecta", "Dicondylia", "Pterygota", "Neoptera", "Paraneoptera",
> "Hemiptera", "Sternorrhyncha", "Aphidiformes", "Aphidomorpha", "Aphidoidea",
> "Aphididae", "Aphidinae", "Macrosiphini", "Acyrthosiphon"};
> mosquito={"Insecta", "Dicondylia", "Pterygota", "Neoptera", "Endopterygota",
> "Diptera", "Nematocera", "Culicimorpha", "Culicoidea"};
> answer = Neoptera
> Thank a 10^6,
> Jason

I'm not sure if this is the most elegant way, but it works for both of
your examples.



Out= USA

Out= Neoptera

Peter Breitfeld, Bad Saulgau, Germany --

  • Prev by Date: Re: Mathematica 8
  • Next by Date: Re: Mathematica 8: first impressions
  • Previous by thread: Re: Finding shared element in two lists
  • Next by thread: Re: Finding shared element in two lists