Skip to content

Conversation

@kanunnykov
Copy link

@kanunnykov kanunnykov commented Apr 28, 2020

Fixes issues #2 and #8

Balanced list of b branch is mixed,
because b.append(..) is used.
b.insert(0, ..) should be used instead.

This code:

from pptree import *

shame = Node("shame")

conscience = Node("conscience", shame)
selfdisgust = Node("selfdisgust", shame)
embarrassment = Node("embarrassment", shame)

selfconsciousness = Node("selfconsciousness", embarrassment)
shamefacedness = Node("shamefacedness", embarrassment)
chagrin = Node("chagrin", embarrassment)
discomfiture = Node("discomfiture", embarrassment)
abashment = Node("abashment", embarrassment)
confusion = Node("confusion", embarrassment)
  
print_tree(shame, horizontal=False)

Currently prints:

 shame                                                                                     
conscience   selfdisgust                                             embarrassment                               
                              selfconsciousness   shamefacedness   chagrin   confusion   abashment   discomfiture

But it should do:

 shame                                                                                     
conscience   selfdisgust                                             embarrassment                               
                              selfconsciousness   shamefacedness   chagrin   discomfiture   abashment   confusion

Balanced list of b branch is mixed,
because b.append(..) is used.
b.insert(0, ..) should be used instead.
@kanunnykov
Copy link
Author

kanunnykov commented Apr 29, 2020

Also this line in balanced_branches changes the order:
a = sorted(children(current_node), key=lambda node: nb_children(node))

The order will stay the same as user defined, if you change it to:
a = children(current_node)

It seems that it works fine without this sorting.

@kanunnykov
Copy link
Author

kanunnykov commented Apr 29, 2020

@clemtoy What do you think about my previous comment? Are there any reasons to change the order specified by client/user/developer? The balancing itself can be done without reordering/sorting.

No need to sort children before balancing.
The order should stay untouched.
@ChestnutHeng
Copy link

do good job!

@sowmith1729
Copy link

@kanunnykov Thanks for the suggestion, It worked for me.

@HuangDell
Copy link

Good job! Thanks for your code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants