I'm using sqlite3 to write some data. However, by default, when a select is made, it returns the information as a list of tuples, which is considerably more difficult to work than if they were dictionaries. Example:
>>> import sqlite3
>>> bd = sqlite3.connect('python.db')
>>> cursor = bd.cursor()
>>> cursor.execute('CREATE TABLE livro (titulo text, autor text)')
>>> cursor.execute('INSERT INTO livro VALUES (?, ?)', ('Manoel', 'Minha história'))
>>> cursor.execute('SELECT * FROM livro')
>>> livros = cursor.fetchall()
>>> livros
[('Manoel', 'Minha história')]
The most obvious solution I can think of would be:
>>> lista_livros = []
>>> for livro in livros:
>>> d = {'autor': livro[0], 'titulo': livro[1],}
>>> lista_livros.append(d)
But in this way the code gets considerably larger when there are many columns. And so, every time there is a change in the columns, it would be necessary to change the code as well.