Lesson 1 of 5 · 2 min
Tables and questions
A database keeps data in tables. SQL describes what you want and leaves how to fetch it to the database. Python ships with a small database called SQLite, so you can practise here.
import sqlite3
db = sqlite3.connect(":memory:")
db.execute("create table runs (model text, task text, score real)")
db.executemany("insert into runs values (?, ?, ?)", [
("small", "tagging", 0.81), ("large", "tagging", 0.90),
("small", "summary", 0.62), ("large", "summary", 0.84),
])
for row in db.execute("select model, score from runs where task = 'summary' order by score desc"):
print(row)
