Question: COMPLETE IN PYTHON PLEASE! In the Tree class, finish the method called get_nodes. This method should take in a piece of data that the method

COMPLETE IN PYTHON PLEASE!

In the Tree class, finish the method called get_nodes. This method should take in a piece of data that the method is searching for, and it should return a list of all of the nodes in the tree that contain that piece of data. The list returned should be in hierarchical order, meaning the list should be ordered from the highest ranking node to lowest ranking node. You can assume that there will be at most one node with the given data on any particular level of the tree.

"""Tree class and tree node class."""

class Node():

"""Node in a tree."""

def __init__(self, data, children=None):

children = children or []

assert isinstance(children, list), \

"children must be a list!"

self.data = data

self.children = children

def __repr__(self):

"""Reader-friendly representation."""

return f""

class Tree():

"""Tree."""

def __init__(self, root):

self.root = root

def __repr__(self):

"""Reader-friendly representation."""

return f""

def get_nodes(self, data):

""" Return a list of nodes with the given data"""

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!