Commit fd41b55f authored by legac's avatar legac
Browse files

Add a method to sort children according to alphabetical order.

parent d7ea70e6
......@@ -159,3 +159,19 @@ class Node(object):
"""
return {'text': self.text, 'children': self.children}
def sort_children(self):
"""sort children according to alphabetical order.
"""
di = {}
for child in self.children:
di[child['text']] = child
names = di.keys()
names.sort(cmp=locale.strcoll)
self.children = []
for name in names:
self.children.append(di[name])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment