<qiyuangong>103_Binary_Tree_Zigzag_Level_Order_Traversal_1.py
def zigzagLevelOrder( root):
    if root is None:
        return []
    q = [[root]]
    for level in q:
        record = []
        for node in level:
            if node.left:
                record.append(node.left)
            if node.right:
                record.append(node.right)
        if record:
            q.append(record)
    res = []
    for index, level in enumerate(q):
        temp = [x.val for x in level]
        if index % 2 == 0:
            res.append(temp)
        else:
            res.append(temp[::-1])
    return res
def sample_funcname ( var_0 ) :
    if var_0 is None :
        return [ ]
    var_2 = [ [ var_0 ] ]
    for var_3 in var_2 :
        var_4 = [ ]
        for var_5 in var_3 :
            if var_5.left :
                var_4.append ( var_5.left )
            if var_5.right :
                var_4.append ( var_5.right )
        if var_4 :
            var_2.append ( var_4 )
    var_9 = [ ]
    for var_11 , var_3 in enumerate ( var_2 ) :
        var_14 = [ var_13.val for var_13 in var_3 ]
        if var_11 % 2 == 0 :
            var_9.append ( var_14 )
        else :
            var_9.append ( var_14 [ : : - 1 ] )
    return var_9
