ZhangZhihui's Blog  
def convert_sqlite_row_to_dict(row, n: int):
    """
    Convert a single row of rows returned by a select query of sqlite3.
    :param row:
    :param n: The number of the first n columns those are grouped by.
    :return:
    """

    row_dict = {}
    for i in range(n - 1, -1, -1):
        if i == n - 1:
            tmp_dict = {f'{row[i]}': row[i+1:]}
        else:
            tmp_dict = {f'{row[i]}': tmp_dict}

    update_dict_cascade(row_dict, tmp_dict)

    return row_dict


def convert_sqlite_rows_to_dict(rows: list, n: int):
    """
    Convert a list of rows returned by a select query of sqlite3.
    :param rows:
    :param n: The number of the first n columns those are grouped by.
    :return:
    """

    rows_dict = {}
    for i, row in enumerate(rows):
        row_dict = convert_sqlite_row_to_dict(row, n)
        update_dict_cascade(rows_dict, row_dict)

    return rows_dict

 

posted on 2022-01-23 22:08  ZhangZhihuiAAA  阅读(64)  评论(0编辑  收藏  举报