class - Odd behaviour with simple tree implementation in python -


class node:     children = {}  sequence = [1,2,3,4,5]  tree = node() node = tree item in sequence:     if item not in node.children:         node.children[item] = node()     node = node.children[item]  print tree.children.keys() 

i want above code output [1], outputs [1, 2, 3, 4, 5]. why this, , how go fixing it?

node.children class attribute. make instance attribute instead.

class node:   def __init__(self):     self.children = {} 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

php - How can I edit my code to echo the data of child's element where my search term was found in, in XMLReader? -