From the course: Python Data Structures: Trees

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Solution: Printing a tree

Solution: Printing a tree - Python Tutorial

From the course: Python Data Structures: Trees

Start my 1-month free trial

Solution: Printing a tree

(upbeat music) - [Instructor] All right, so I hope you had fun with this one, and made something that prints out your trees satisfactorily. We're going to be doing a lot of tree printing in the next two chapters. So whether you use your solution or want to use mine, doesn't matter, but you do need something to print out your trees. So I'll walk you through what I came up with. The first thing we want to do, and by the way, this is all going to be in the tree class, not the node class that we've been mostly working with. But the first thing that we're going to want to do is print out the tree's name. You know, we added those name attributes to the trees, might as well start using them. I also added a feature where you can pass in an optional label, just for this one instance of printing. And it will also print out that, you know, maybe we could put like a fun dash in there or something. Next thing is going to be to get…

Contents