diff --git a/pptree/pptree.py b/pptree/pptree.py index 76abd4b..b5e2dc2 100644 --- a/pptree/pptree.py +++ b/pptree/pptree.py @@ -30,10 +30,10 @@ def balanced_branches(current_node): size_branch = {child: nb_children(child) for child in children(current_node)} """ Creation of balanced lists for "a" branch and "b" branch. """ - a = sorted(children(current_node), key=lambda node: nb_children(node)) + a = children(current_node) b = [] while a and sum(size_branch[node] for node in b) < sum(size_branch[node] for node in a): - b.append(a.pop()) + b.insert(0, a.pop()) return a, b