0
2つの入力を受け入れる "common_ancestor()"という関数を作成しようとしています。最初は文字列タクサ名のリスト、2番目は系統樹辞書です。入力リストにあるすべての 種の中で、最も近い共通の祖先である分類群の名前を示す文字列を返します。 list_ancestorsという別の関数を既に作成しています。この関数はリストの要素の一般的な先祖です。また、私が働いている辞書を持っています。Pythonでネストされたツリー辞書のcommon_ancestor関数
tax_dict = {
'Pan troglodytes': 'Hominoidea', 'Pongo abelii': 'Hominoidea',
'Hominoidea': 'Simiiformes', 'Simiiformes': 'Haplorrhini',
'Tarsius tarsier': 'Tarsiiformes', 'Haplorrhini': 'Primates',
'Tarsiiformes': 'Haplorrhini', 'Loris tardigradus':'Lorisidae',
'Lorisidae': 'Strepsirrhini', 'Strepsirrhini': 'Primates',
'Allocebus trichotis': 'Lemuriformes', 'Lemuriformes': 'Strepsirrhini',
'Galago alleni': 'Lorisiformes', 'Lorisiformes': 'Strepsirrhini',
'Galago moholi': 'Lorisiformes'
}
def halfroot(tree):
taxon = random.choice(list(tree))
result = [taxon]
for i in range(0,len(tree)):
result.append(tree.get(taxon))
taxon = tree.get(taxon)
return result
def root(tree):
rootlist = halfroot(tree)
rootlist2 = rootlist[::-1]
newlist = []
for e in range(0,len(rootlist)):
if rootlist2[e] != None:
newlist.append(rootlist2[e])
return newlist[0]
def list_ancestors(taxon, tree):
result = [taxon]
while taxon != root(tree):
result.append(tree.get(taxon))
taxon = tree.get(taxon)
return result
def common_ancestors(inputlist,tree)
biglist1 = []
for i in range(0,len(listname)):
biglist1.append(list_ancestors(listname[i],tree))
"continue so that I get three separate lists where i can cross reference all elements from the first list to every other list to find a common ancestor "
結果は
一つの方法は、それぞれの種のためのすべての祖先を集めるセットでそれらを配置し、彼らが持っているものを得るために交差点を取得することですprint(common_ancestor([’Hominoidea’, ’Pan troglodytes’,’Lorisiformes’], tax_dict)
Output: ’Primates’"
ようこそStackOverflow。まず、あなたが試したこと、そしてあなたが不足しているところを示してください。ヘルプについては、[How to ask](https://stackoverflow.com/help/how-to-ask)をご覧ください。 –
Homework Helpのように疑わしいように見えます。 – Quirk