def sort_fields(fields):
    """Sort fields by their column_number but put children after parents.

    """
    fathers = [(key, val) for key, val in
               sorted(fields.items(), key=lambda k: k[1]['column_number'])
               if 'auto_generated' not in val]
    children = [(key, val) for key, val in
                sorted(fields.items(), key=lambda k: k[1]['column_number'])
                if 'auto_generated' in val]
    children.reverse()
    fathers_keys = [father[0] for father in fathers]
    for child in children:
        try:
            index = fathers_keys.index(child[1]['parent_ids'][0])
        except __HOLE__:
            index = -1

        if index >= 0:
            fathers.insert(index + 1, child)
        else:
            fathers.append(child)
    return fathers
dataset/ETHPy150Open bigmlcom/python/bigml/util.py/sort_fields