Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7749165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:58:20+00:00 2026-06-01T10:58:20+00:00

Traceback (most recent call last): File <pyshell#9>, line 1, in <module> ClosestCommonAncestor(A,C,x) File C:\x\x.py,

  • 0
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    ClosestCommonAncestor("A","C",x)
  File "C:\x\x.py", line 149, in ClosestCommonAncestor
    b = tree[otu2][0]
KeyError: ('ADBFGC', 14.5)

This is the function that returns the error.

def ClosestCommonAncestor32 (otu1,otu2,tree):
    while True:
        a = tree[otu1][0][0]
        while True:
           b = tree[otu2][0]
            if a == b:
                return a
            otu2 = b
        otu1 = a

this is the tree input

{'A': [('AD', 4.0), None, None], 'C': [('ADBFGC', 14.5), None, None], 'B': [('BF', 0.5), None, None], 'E': [('ADBFGCE', 17.0), None, None], 'D': [('AD', 4.0), None, None], 'G': [('BFG', 6.25), None, None], 'F': [('BF', 0.5), None, None], 'ADBFG': [('ADBFGC', 6.25), ('AD', 4.25), ('BFG', 2.0)], 'BF': [('BFG', 5.75), ('B', 0.5), ('F', 0.5)], 'ADBFGC': [('ADBFGCE', 2.5), ('ADBFG', 6.25), ('C', 14.5)], 'ADBFGCE': [None, ('ADBFGC', 2.5), ('E', 17.0)], 'BFG': [('ADBFG', 2.0), ('BF', 5.75), ('G', 6.25)], 'AD': [('ADBFG', 4.25), ('A', 4.0), ('D', 4.0)]}

I don’t understand this, I thought Keyerror was when it requested a key that didn’t exist?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:58:21+00:00Added an answer on June 1, 2026 at 10:58 am

    I thought Keyerror was when it requested a key that didn’t exist?

    That’s right.

    However, there is no key ('ADBFGC', 14.5) in your dictionary. The tuple is indeed present in one of the value lists, but it’s not a key. The dictionary’s keys are 'A', 'C', 'ADBFGC' etc.

    To just use the first element of the tuple to index into the dictionary, write tree[otu2[0]].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Traceback (most recent call last): File <pyshell#80>, line 1, in <module> do_work() File C:\pythonwork\readthefile080410.py,
Traceback (most recent call last): File <pyshell#27>, line 1, in <module> server = NNTP('http://www.news.readfreenews.net')
>>> import pylibmc Traceback (most recent call last): File <stdin>, line 1, in <module>
from lines import lines Traceback (most recent call last): File <pyshell#4>, line 1, in
>>> myList[1] 'from form' >>> myList[1].append(s) Traceback (most recent call last): File "<pyshell#144>", line
ho-fe3fdd00-12:~ Sam$ easy_install BeautifulSoup Traceback (most recent call last): File /usr/bin/easy_install, line 8, in
Consider the following stacktrace: In [3]: f.clean() --------------------------------------------------------------------------- AttributeError Traceback (most recent call last)
2009-06-30 23:36:28,483 ERROR appcfg.py:1272 An unexpected error occurred. Aborting. Traceback (most recent call last):
This doesn't work: import re re.sub('\\', '/', C:\\Users\\Judge) Error: Traceback (most recent call last):
Why am I getting no attribute __getitem__ error for dictionary: Traceback (most recent call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.