How to make a variable assignment in a loop?

I have a loop of the form:
for i in ids:
 sql = """SELECT clevel,chel,ctail,cgun,carm,cfoot FROM cats WHERE id=?"""
 cur.execute(sql, [(i)])
 setp = cur.fetchone()
 per_th = {'clevel': setp[0], 'chel': setp[1],'ctail': setp[2],'cgun': setp[3],'carm':setp[4],'cfoot':setp[5]}

As a result, I get a dictionary per_th with values, but I have two people tell me how can I in the cycle assign different names for a function, that is, that I have in fact had two dictionary per_th and per_th2
March 19th 20 at 09:26
1 answer
March 19th 20 at 09:28
List to use:
data = []
for i in ids:
 'clevel': setp[0],
 'chel': setp[1],
 'ctail': setp[2],
 'cgun': setp[3],
 'carm': setp[4],
 'cfoot': setp[5],

Yes, and the dictionary can be easier to shape:
con = sqlite3.connect(...)
con.row_factory = lambda c, r: {k: r[i] for i, k, *_ in enumerate(cursor.description)}
cur = con.cursor()



Find more questions by tags SQLitePython