[Tutor] Binary Tree Printing Woes
Chimp
tutor@python.org
Sat Jun 7 05:51:01 2003
* Alan Gauld <alan.gauld@blueyonder.co.uk> [030606 23:03]:
> > .....But how come the print_tree() function - which ALSO returns
> > None works just dandy?!
>
> Good question and I asked myself the same thing.
>
> I didn't see an obvious answer but assumed it must
> be some strange combination of calling pattern. I suspect
> a bigger tree might give a different answer, a 3 node one
> isn't enough to test all scenarios. A cop out sorry! :-)
I tried one with a bajillion nodes, but alas, same effect. *sigh*
I'll be busy all weekend, but I'll look into it again, pull in some
markers on the IRC/ICQ grapewine, cut some shady deals with people in
the know and get back to the list with a solution, don't you worry.
Ain't gonna let this bugger ruin my Coding Experience(tm).
> > But how do I rewrite the function so make the "print" ignore it?
> Just call the function, since it does its own printing you
> don't need to! Alternatively, and better practice, make the
> function return a list of values and you then print those
> outside the function..
Sorry for screwing up that sentence. *blush* I like the idea of building
up a list and return it - maybe not for a lousy print statement(!), but
in general. I'm not sure I can handle it recursively, but I'll get my
grubby paws dirty over the weekend and we'll see what comes crawling out
of the lab, ha ha!
Later,
-- Chimp
--
o _ _ _
------- __o __o /\_ _ \\o (_)\__/o (_) -o)
----- _`\<,_ _`\<,_ _>(_) (_)/<_ \_| \ _|/' \/ /\\
---- (_)/ (_) (_)/ (_) (_) (_) (_) (_)' _\o_ _\_v
Don't Drive And Pray - Listen To InfidelGuy.com And Rock Your Mind