1def dict_factory(cursor, row):
2 d = {}
3 for idx, col in enumerate(cursor.description):
4 d[col[0]] = row[idx]
5 return d
6
7conn = sqlite3.connect("data.db")
8conn.row_factory = dict_factory
9db = conn.cursor()
10print(db.execute("SELECT * FROM table"))
11>>> [{'col1': 'val1', 'col2': 'val2'}, {'col1': 'val3', 'col2': 'val4'}]