I am new to python. Here I was testing on example where varialbe wordlist has been used in loop.
Do I need to declare it manually before using it? or it would get declared runtime?
I even tried with manual declaration but then it remains empty.
I am following this example: http://www.sjwhitworth.com/sentiment-analysis-in-python-using-nltk/
If I directly use this:
wordlist = [i for i in wordlist if not i in stopwords.words('english')]
wordlist = [i for i in wordlist if not i in customstopwords]
it gives error:
wordlist = [i for i in wordlist if not i in stopwords.words('english')]
NameError: name 'wordlist' is not defined
I manually declared wordlist like this
wordlist = []
but then it remain empty in this case:
wordlist = []
wordlist = [i for i in wordlist if not i in stopwords.words('english')]
wordlist = [i for i in wordlist if not i in customstopwords]
print wordlist
What wrong I am doing here?
wordlistbefore you use it. If it's not set, it gives the error you have. If you set it to an empty list, it will remain empty, because the list comprehensions don't add anything to the list