求问一道关于二叉树的python题目,大学刚开始学python,求教

需要写一个函数word_tree(),能执行以下操作

s = "spam eggs spam eggs ham spam hamham Spam"
t = Node('spam', 3, Node('eggs', 2, Node('Spam', 1, None,
None), Node('ham', 1, None, Node('hamham', 1,
None, None))), None)
str(word_tree(s)) == str(t)
True