fdutils/html.py
def _create_from_table(labels, rows, row_names=(), cast_types=(int, float, str), as_list=False, key_format=None):
    """ given labels and rows creates a dictionary
        where each row is zipped with labels
    """
    ret = ordered_dict() if not as_list else list()
    labels = [l for l in labels if l]
    row_names = row_names or [r[0] for r in rows]
    max_rows_length = max(len(r) for r in rows)
    all_rows_same = all(len(r) == max_rows_length for r in rows)
    for i, row in enumerate(rows):
        for j, v in enumerate(row):
            row[j] = cast(v, *cast_types)

        if max_rows_length != len(labels):
            data = dict(zip(labels, row[len(row) - len(labels):]))
        elif len(labels) == 2:
            data = row[-1] if len(row) == 2 else None
        elif all_rows_same:
            data = dict(zip(labels, row))
        else:
            data = dict(zip(labels[1:], row[len(row[1:]) - len(labels[1:]):]))

        if as_list:
            ret.append(data)
        else:
            key = key_format(row_names[i]) if key_format else row_names[i]
            ret[key] = data

    return ret
 given labels and rows creates a dictionary
        where each row is zipped with labels
    
given labels and rows creates a dictionary
where each row is zipped with labels
given labels and rows creates a dictionary where each row is zipped with labels
def _create_from_table(labels, rows, row_names=(), cast_types=(int, float, str), as_list=False, key_format=None):
    ret = ordered_dict() if not as_list else list()
    labels = [l for l in labels if l]
    row_names = row_names or [r[0] for r in rows]
    max_rows_length = max(len(r) for r in rows)
    all_rows_same = all(len(r) == max_rows_length for r in rows)
    for i, row in enumerate(rows):
        for j, v in enumerate(row):
            row[j] = cast(v, *cast_types)
        if max_rows_length != len(labels):
            data = dict(zip(labels, row[len(row) - len(labels):]))
        elif len(labels) == 2:
            data = row[-1] if len(row) == 2 else None
        elif all_rows_same:
            data = dict(zip(labels, row))
        else:
            data = dict(zip(labels[1:], row[len(row[1:]) - len(labels[1:]):]))
        if as_list:
            ret.append(data)
        else:
            key = key_format(row_names[i]) if key_format else row_names[i]
            ret[key] = data
    return ret
def _create_from_table ( labels , rows , row_names = ( ) , cast_types = ( int , float , str ) , as_list = False , key_format = None ) : ret = ordered_dict ( ) if not as_list else list ( ) labels = [ l for l in labels if l ] row_names = row_names or [ r [ 0 ] for r in rows ] max_rows_length = max ( len ( r ) for r in rows ) all_rows_same = all ( len ( r ) == max_rows_length for r in rows ) for i , row in enumerate ( rows ) : for j , v in enumerate ( row ) : row [ j ] = cast ( v , * cast_types ) if max_rows_length != len ( labels ) : data = dict ( zip ( labels , row [ len ( row ) - len ( labels ) : ] ) ) elif len ( labels ) == 2 : data = row [ - 1 ] if len ( row ) == 2 else None elif all_rows_same : data = dict ( zip ( labels , row ) ) else : data = dict ( zip ( labels [ 1 : ] , row [ len ( row [ 1 : ] ) - len ( labels [ 1 : ] ) : ] ) ) if as_list : ret . append ( data ) else : key = key_format ( row_names [ i ] ) if key_format else row_names [ i ] ret [ key ] = data return ret
given labels and rows creates a dictionary
where each row is zipped with labels
given labels and rows creates a dictionary where each row is zipped with labels
""" given labels and rows creates a dictionary
        where each row is zipped with labels
    """
labels
rows
row_names
cast_types
as_list
key_format