The error is
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <listcomp>
TypeError: argument of type 'WordListCorpusReader' is not iterable
The error is in the filteredList comprehension but I can't figure out why and how to write it so it actually works.
Any help is appreciated or a pointer to where can I find docs to work through this.
#!/usr/bin/env python3
# Imports json module
import json
# Loads the books we downloaded
from nltk.book import *
# Import stopwords list for English
from nltk.corpus import stopwords
# Set the stopwords words to English
stop = set(stopwords.words('english'))
# Creates a frequency distribution for
fdist1 = FreqDist(text1)
# Creates a list of the 200 most common words on Moby Dick
mostCommon = fdist1.most_common(200)
# Print out most common
# print(mostCommon)
filteredList = [w for w[0] in mostCommon if w not in stopwords]
# Write o utput to file
with open('cloud.json', "w") as f:
f.write(json.dumps(filteredList, indent=2))