Search code examples
pythonlistsqliteselectstore

storing select results in an array


I am using python sqlite to search on specific match in a certain column, once found a match, need to store the other columns' values in a python variables for further use. what I can't do is to store the data from the select query in list

for z in range(0,y):
    for m,n in cr.execute ("select English,Tagger from POS where Arabic=?",(x[z],)):
        h[z]=m
        f[z]=n

both m and n variables returning correct values in each iteration in the for loop but I can't store them in both h and f for further use


Solution

  • Please describe the problem in more detail.

    • What is the error that you get?
    • Did you declared h, f variables as list of length y before you attempt to write into the list? - eg. h = [None] * z
    • Or you can use dict h = {} and than h[z] = m
    • Or if you don't need to know the z value just append to empty list - eg. h = [] and h.append(m)