0

I am new to python trying to work with NLTK.

I am trying to figure out why the tuple of the words is going empty for the following piece of code.

import nltk
import random
from nltk.corpus import movie_reviews

#Empty feature tuple
tupleDocuments = []

#Empty list of words
listWords = []

#For every words in the files, categorizing the list of words in one category
for category in movie_reviews.categories():
    for fileid in movie_reviews.fileids(category):
        #Running for all words in one file
        for word in movie_reviews.words(fileid):
            #Convert all the words to lower case
            word = word.lower()
            #Appending all the words in the file to a list
            listWords.append(word)
            #print the list of words
            #print(listWords)
        #Adding the list and the category as tuple into feature    
        tupleDocuments.append([listWords,category])
        #Print Tuple Document
        #print(tupleDocuments)
        #Clearing the list
        listWords.clear()

#randomizing all the sets
random.shuffle(tupleDocuments)

#Printing the 2nd tuple of features
print(tupleDocuments[2])
Avirup Das
  • 189
  • 1
  • 3
  • 15

0 Answers0