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 7683355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:46:24+00:00 2026-05-31T18:46:24+00:00

def Ancestors (otu,tree): if tree[otu][0][0] == None: return [] else: return [otu,tree[otu][0][0]] + Ancestors

  • 0
def Ancestors (otu,tree):
    if tree[otu][0][0] == None:
       return []
    else:
        return [otu,tree[otu][0][0]] + Ancestors (tree[otu][0][0],tree)

The problem essentially is that at some point, the function tries to call a something which is None, this happens instead of the function returning the list that I want. I thought the if statement had accounted for that, but it would seem I was wrong. Any advice?

Traceback (most recent call last):
  File "<pyshell#41>", line 1, in <module>
    Ancestors('A',a)
  File "C:\x.py", line 129, in Ancestors
    return [otu,tree[otu][0][0]] + Ancestors (tree[otu][0][0],tree)
  File "C:\x.py", line 129, in Ancestors
    return [otu,tree[otu][0][0]] + Ancestors (tree[otu][0][0],tree)
  File "C:\x.py", line 129, in Ancestors
    return [otu,tree[otu][0][0]] + Ancestors (tree[otu][0][0],tree)
  File "C:\x.py", line 129, in Ancestors
    return [otu,tree[otu][0][0]] + Ancestors (tree[otu][0][0],tree)
  File "C:\x.py", line 126, in Ancestors
    if tree[otu][0][0] == None:
TypeError: 'NoneType' object is not subscriptable

This is what tree is

{'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)]}

with otu referring to any of the strings in the tree.

  • 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-05-31T18:46:25+00:00Added an answer on May 31, 2026 at 6:46 pm

    This simply means that either tree, tree[otu], or tree[otu][0] evaluates to None, and as such is not subscriptable. Most likely tree[otu] or tree[otu][0]. Track it down with some simple debugging like this:

    def Ancestors (otu,tree):
        try:
            tree[otu][0][0]
        except TypeError:
            print otu, tre[otu]
            raise
        #etc...
    

    or pdb

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

Sidebar

Related Questions

def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails
def test_method [a, b, c].map {|i| yield(i) } end If I call test_method like
def self.get(server) return unless server server = server.to_s if klass = @handlers[server] obj =
def any? if block_given? method_missing(:any?) { |*block_args| yield(*block_args) } else !empty? end end In
def record return unless @supported klasses = profile_options[:formats].map { |f| RubyProf.const_get(#{f.to_s.camelize}Printer) }.compact klasses.each do
def remove_section(alist, start, end): Return a copy of alist removing the section from start
def common_elements(list1, list2): Return a list containing the elements which are in both list1
Suppose we have the following class hierarchy: class ClassA: @property def foo(self): return hello
def getStuff(x): return 'stuff'+x def getData(x): return 'data'+x thefunctions = [] thefunctions.append(getStuff) thefunctions.append(getData) for
class Class def mixin_ancestors(include_ancestors=true) ancestors.take_while {|a| include_ancestors || a != superclass }. select {|ancestor|

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.