Re: Finding shared element in two lists
- To: mathgroup at smc.vnet.net
- Subject: [mg114088] Re: Finding shared element in two lists
- From: James Stein <mathgroup at stein.org>
- Date: Tue, 23 Nov 2010 05:59:25 -0500 (EST)
Assuming the two input lists share a common prefix, you can use this: SequenceAlignment [ myhouse, friendshouse] [ [ 1, -1 ] ] SequenceAlignment [ aphid, mosquito] [ [ 1, -1 ] ] Like you, I am more comfortable with procedural programming, partly because that's what I learned first, but also because I don't know how to employ error checks in functional programming. For example, if one of your lists erroneously contains "insect" instead of "insecta", the result is not only wrong, but it has unexpected structure. On Mon, Nov 22, 2010 at 4:40 AM, Jason Ebaugh <ebaughjason at gmail.com> 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 > > > -- > Jason Ebaugh, PhD. > > Personal communications: ebaughjason at gmail.com > Business communications: jason.ebaugh at apisscientific.com > Dissertation: http://hdl.handle.net/2142/13005 > Linkedin: > > http://www.linkedin.com/profile?viewProfile=&key=22842228&locale=en_US&trk=tab_pro > Need bioinformatics help? www.apisscientific.com > > >