binary tree level order traversal

🏠
 1 from binary_tree_node import BinaryTreeNode as N
 2 from test_framework import generic_test
 3 
 4 
 5 def lev(t):
 6     result = []
 7     if not t:
 8         return result
 9     s = [t]
10     while s:
11         result.append([x.data for x in s])
12         level_nodes = []
13         for curr in s:
14             if curr.left:
15                 level_nodes.append(curr.left)
16             if curr.right:
17                 level_nodes.append(curr.right)
18         s = level_nodes
19     return result
20 
21 
22 if __name__ == "__main__":
23     exit(
24         generic_test.generic_test_main(
25             "tree_level_order.py", "tree_level_order.tsv", lev
26         )
27     )