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]}
 print(per_th)

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
Solution
List to use:
data = []
for i in ids:
...
data.append({
 '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()

...

data.append(cur.fetchone())

Find more questions by tags SQLitePython