zed khaleghi
zed khaleghi

Reputation: 27

'set' object cannot be interpreted as an integer

I have the following python code:

text = "this’s a sent tokenize test. this is sent two. is this sent three? sent 4 is cool! Now it’s your turn."
from nltk.tokenize import sent_tokenize
sent_tokenize_list = sent_tokenize(text)

import numpy as np

lenDoc=len(sent_tokenize_list)

features={'position','rate'}
score = np.empty((lenDoc, 2), dtype=object)
score=[[0 for x in range(sent_tokenize_list)] for y in range(features)]
for i,sentence in enumerate(sent_tokenize_list):
    score[i,features].append((lenDoc-i)/lenDoc)

But it results in the following error:

 TypeError                                 Traceback (most recent call last) <ipython-input-27-c53da2b2ab02> in <module>()
      13 
      14 
 ---> 15 score=[[0 for x in range(sent_tokenize_list)] for y in range(features)]
      16 for i,sentence in enumerate(sent_tokenize_list):
      17     score[i,features].append((lenDoc-i)/lenDoc)

 TypeError: 'set' object cannot be interpreted as an integer

Upvotes: 1

Views: 4222

Answers (1)

Arash Rohani
Arash Rohani

Reputation: 1014

range() takes int values. features is a set so it throws an error. you made the same mistake with range(sent_tokenize_list). sent_tokenize_list is a list value not an int. If you want x and y to be indexes of features and sent_tokenize_list then you have to use this: score=[[0 for x in range(len(sent_tokenize_list))] for y in range(len(features))] But if you want x and y to be values of features and sent_tokenize_list then you have to remove range() from that line.

Upvotes: 1

Related Questions