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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:54:49+00:00 2026-06-15T08:54:49+00:00

Solved: It seems that the problem only occurs with PythonWin. I ran everything through

  • 0

Solved: It seems that the problem only occurs with PythonWin. I ran everything through the IDLE’s python shell and it worked just fine. Must be a bug with PythonWin and not the code itself.

I can’t seem to figure out why the following code is giving me a TypeError: 'type' object is not iterable

pastebin: http://pastebin.com/VFZYY4v0

def genList(self):
    #recursively generates a sorted list of child node values
    numList = []
    if self.leftChild != 'none':
        numList.extend(self.leftChild.genList())  #error
    numList.extend(list((self.Value,)))
    if self.rightChild != 'none':
        numList.extend(self.rightChild.genList()) #error
    return numList

code that adds child nodes (works correctly)

def addChild(self, child):
    #add a child node. working
    if child.Value < self.Value:
        if self.leftChild == 'none':
            self.leftChild = child
            child.parent = self
        else:
            self.leftChild.addChild(child)
    elif child.Value > self.Value:
        if self.rightChild == 'none':
            self.rightChild = child
            child.parent = self
        else:
            self.rightChild.addChild(child)

Any help would be appreciated.

Full interpreter session:
>>> import BinTreeNode as BTN
>>> node1 = BTN.BinaryTreeNode(5)
>>> node2 = BTN.BinaryTreeNode(2)
>>> node3 = BTN.BinaryTreeNode(12)
>>> node3 = BTN.BinaryTreeNode(16)
>>> node4 = BTN.BinaryTreeNode(4)
>>> node5 = BTN.BinaryTreeNode(13)
>>> node1.addChild(node2)
>>> node1.addChild(node3)
>>> node1.addChild(node4)
>>> node1.addChild(node5)
>>> node4.genList()
<class ‘list’>
>>> node1.genList()
Traceback (most recent call last):
File “<interactive input>”, line 1, in <module>
File “C:…\python\BinTreeNode.py”, line 47, in genList
numList.extend(self.leftChild.genList()) #error
File “C:…\python\BinTreeNode.py”, line 52, in genList
TypeError: ‘type’ object is not iterable

  • 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-15T08:54:50+00:00Added an answer on June 15, 2026 at 8:54 am

    There is nothing in your examples to indicate where the problem is coming from, but what it means is that somehow you are returning an object type and not an object instance. All I can offer at this point is to suggest another way to rework the genList() method and see if it magically fixes your issue.

    You could try passing along the same result list through the recursion, instead of returning lots of temporary ones:

    def genList(self, numList=None):
        if numList is None:
            numList = []
    
        if self.leftChild != 'none':
            self.leftChild.genList(numList)
    
        numList.append(self.Value)
    
        if self.rightChild != 'none':
            self.rightChild.genList(numList)
    
        return numList
    
    results = rootNode.genList()
    

    Also, is there a reason you are using 'none' instead of None ? I would just use a None instead of a string.

    My suggested edits to your version are here: http://pastebin.com/FGf8Lcdu

    And here is the output of your same interpreter code, under python3.3:

    In [1]: %cpaste
    Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
    :>>> import BinTreeNode as BTN
    :>>> node1 = BTN.BinaryTreeNode(5)
    :>>> node2 = BTN.BinaryTreeNode(2)
    :>>> node3 = BTN.BinaryTreeNode(12)
    :>>> node3 = BTN.BinaryTreeNode(16)
    :>>> node4 = BTN.BinaryTreeNode(4)
    :>>> node5 = BTN.BinaryTreeNode(13)
    :>>> node1.addChild(node2)
    :>>> node1.addChild(node3)
    :>>> node1.addChild(node4)
    :>>> node1.addChild(node5)
    :<EOF>
    
    In [2]: node4.genList()
    Out[2]: [4]
    
    In [3]: node1.genList()
    Out[3]: [2, 4, 5, 13, 16]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interesting problem that seems to be eluding me. Mono's xsp4 only
I've got abit of a strange problem, that I just can't seem to solve!
Edit: [Solved] : It seems that the getTableCellRendererComponent of the CustomTableCellRenderer is called every
I have an extremely odd problem in my JUnit tests that I just can't
I'm asking this question because I finally solved a problem that I have been
I have a problem with file permissions on executing files in Windows that seems
NOTE: Solved my own problem, it seems. See the edits. I am trying to
I have stumbled upon an interesting problem/bug that I eventually solved, but the solution
I have a strange problem that I can't seem to solve. I've quite a
I am struggling for days to solve this problem and it seems i cant

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.