I met a problem with a old python 2x code syntax which produced the error:
print (name, tree.keys()[0])
TypeError: 'dict_keys' object is not subscriptable
and the old python 2x code is:
def printTree(self,tree,name):
if type(tree) == dict:
print name, tree.keys()[0]
for item in tree.values()[0].keys():
print name, item
self.printTree(tree.values()[0][item], name + "\t")
else:
print name, "\t->\t", tree
How can I change these syntax in using python 3x? I have tried list() how ever the self.printTree(tree.values()[0][item], name + "\t")
still has the dict_value error.
The full code: https://homepages.ecs.vuw.ac.nz/~marslast/Code/Ch12/dtree.py
Thank you for your help.