def levelOrder(self, root):
        result = []
        q = []
        if root:
            q.append(root)

        while q:
            length = len(q)
            # cur_level = []
            for i in range(length):
                cur = q[i]
                if cur.left:
                    q.append(cur.left)
                if cur.right:
                    q.append(cur.right)
            result.append(map(lambda x: x.val, q[:length]))  # no need to create a new list
            q = q[length:]  # no need to create a new list
        return result
Queue
dataset/ETHPy150Open algorhythms/LeetCode/102 Binary Tree Level Order Traversal.py/Solution.levelOrder