question archive Common_ancestor( ) The function common_ancestor( ) takes two inputs: the first is a list of string taxa names, and the second is a phylogenetic tree dictionary

Common_ancestor( ) The function common_ancestor( ) takes two inputs: the first is a list of string taxa names, and the second is a phylogenetic tree dictionary

Subject:Computer SciencePrice: Bought3

Common_ancestor( )

The function common_ancestor( ) takes two inputs: the first is a list of string taxa names, and the second is a phylogenetic tree dictionary.

It returns a string giving the name of the taxon that is the closest common ancestor of all the species in the input list.

The empty list is a legal input, and should return the empty list.

A list with just one taxon is a legal input, and should return that taxon.

This one is complicated. Here's one way to do it for the general case of a list of length at least two:

Make a list of all the ancestor lists for every taxon in the input list, using list_ancestors().

For the first list in that list, call it "list0" (ancestors of one particular taxon), go through the taxa in that list in order:

if a taxon from "list0" is in every other list in the list of list of answers, then that is the first common ancestor, and we're done

otherwise, try the next taxon in list0

I already have the code below I just need a code without the if all statement def common_ancestor(l, tree):    """returns the common ancestor of all taxa in l in tree.  If l is    empty, returns the empty list.  If l has one element, returns    that element."""    if not l:        return []    if len(l) == 1:        return l[0]    ancestor_lists = [list_ancestors(taxon, tree) for taxon in l]    for ancestor in ancestor_lists[0]:        if all([ancestor in lst for lst in ancestor_lists]):            return ancestor

 

 

Please give correct answer only with explanation. Please answer asap within 45 minutes. It's urgent

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Related Questions