python list is out of range at iteration 14?
<p>i have a list of indexes that point a term in database</p>

<p>Here is my code:</p>

<pre><code>for doc in TSS:
    tokens = word_tokenize(doc[1])
    tokens = [token.lower() for token in tokens if len(token) &gt; 2]
    tokens = [token for token in tokens if token not in words]
    tokens = [stemmer.stem(token) for token in tokens]
    final_tokens.extend(tokens)
    sql = """SELECT id_term FROM tss_terms WHERE tss_terms.term IN %s"""
    pram = [final_tokens]
    cursor.execute(sql, pram)
    ids = list(cursor.fetchall())
    count = 0
    data[doc[1]] = {'tf': {}, 'ntf': {}}
    for token in final_tokens:
        data[doc[1]]['tf'][token] = freq(token,final_tokens)
        data[doc[1]]['ntf'][token] = tf(token,final_tokens)
        query = """INSERT INTO tss_term_freq(id_term,id_doc,tf,normalized_tf)VALUES(%s,%s,%s,%s)"""
        param = [ids[count],doc[0],data[doc[1]]['tf'][token],data[doc[1]]['ntf'][token]]
        #cursor.execute(query, param)
        count = count + 1
    del final_tokens[:]
    print count
</code></pre>

<p>the <code>ids</code> list always get <code>error : list index out of range</code> at the 14th iteration.</p>

<p>the values of TSS[13] are like this:</p>

<pre><code>(5927L, 'PERHITUNGAN POHON KELAPA SAWIT PADA CITRA FOTO UDARA\r\nYANG BERBASIS BENTUK MAHKOTA POHON')
</code></pre>

<p>then the values of TSS[14] are like this:</p>

<pre><code>(6698L, 'SINKRONISASI WAKTU METER LISTRIK BERDASARKAN GLOBAL POSITIONING SYSTEM (GPS) PADA SUPERVISORY CONTROL AND DATA ACQUISITION (SCADA) BERBASIS WEB')
</code></pre>

<p>TSS contains document ids and titles of thesis in my university</p>

<p>can anyone show my mistake and fix it?</p>

<p>Please help :(</p>

<p>The way the list "id" is declared is wrong.
I didnt get what you are doing there.
But if want to store all the values returned by fetchall() function then use for loop for doing it.
Declare an empty list id.
id = [ ]
Use a for loop for taking all the values.
And to save the value in list use 
id.append(value)</p>

python