TypeError: list indices must be integers, not tuple in Python SVD model
<p>I am testing a recommender based on SVD model. But I got an error message after running it as below: </p>

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

<pre><code>import sys 
from sys import argv
import csv
import recsys.algorithm
recsys.algorithm.VERBOSE = True
from recsys.algorithm.factorize import SVD
from recsys.datamodel.data import Data

likes = []
with open('/Users/xps13mynotebook/Desktop/w2v/likes.tsv', 'r') as f:
    for line in f.readlines():
        username,user_likes = line.strip().split('\t')
        likes.append((username,user_likes))
data = Data()
VALUE = 1.0
for username in likes:
    for user_likes in likes[username]:
        data.add_tuple((VALUE, username, user_likes)) # Tuple format is: &lt;value, row, column&gt;

svd = SVD()
svd.set_data(data)
k = 5 
svd.compute(k=k, min_values=3, pre_normalize=None, mean_center=False, post_normalize=True)

svd.similar('sheila')
</code></pre>

<p>Error:</p>

<pre><code>TypeError                                 Traceback (most recent call last)
&lt;ipython-input-30-913000ff4e0e&gt; in &lt;module&gt;()
     10 VALUE = 1.0
     11 for username in likes:
---&gt; 12     for user_likes in likes[username]:
     13         data.add_tuple((VALUE, username, user_likes)) # Tuple format is: &lt;value, row, column&gt;
     14 

TypeError: list indices must be integers, not tuple 
</code></pre>

<p>The TypeError is saying that you can't access element with a list when you provide it with a tuple, it needs an integer that is the position in the list.</p>

<p>Now why is this happening?</p>

<pre><code>likes.append((username,user_likes))
</code></pre>

<p>and</p>

<pre><code>for username in likes:
</code></pre>

<p>likes is a list where tuples are stored, so your username in like is something like <code>("mike", 6)</code>.</p>

<p>Then you are passing that to a list as a position of element. That's why you are getting an error. I don't know exactly what you want your code to do, but right now it's pretty much nonsense</p>

python tuples svd