[Tutor] positional argument error
shubham sinha
upwkwd at gmail.com
Sun Apr 26 11:30:40 EDT 2020
hello,
I am new to python and as a doing excercise I got an error that is
mentioned below:
please help me through that.
q. create a "word cloud" from a text by writing a script. This script needs
to process the text, remove punctuation, ignore case and words that do not
contain all alphabets, count the frequencies, and ignore uninteresting or
irrelevant words. A dictionary is the output of the calculate_frequencies
function.
my code:
def calculate_frequencies(file_contents):
# Here is a list of punctuations and uninteresting words you can use to
process your text
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
uninteresting_words = ["the", "a", "to", "if", "is", "it", "of", "and",
"or", "an", "as", "i", "me", "my", \
"we", "our", "ours", "you", "your", "yours", "he", "she", "him", "his",
"her", "hers", "its", "they", "them", \
"their", "what", "which", "who", "whom", "this", "that", "am", "are",
"was", "were", "be", "been", "being", \
"have", "has", "had", "do", "does", "did", "but", "at", "by", "with",
"from", "here", "when", "where", "how", \
"all", "any", "both", "each", "few", "more", "some", "such", "no",
"nor", "too", "very", "can", "will", "just"]
# LEARNER CODE START HERE
result = {}
contents_split = file_contents.split()
def generate_from_frequencies(file_contents):
for word in contents_split:
if word in uninteresting_words:
pass
else:
for letter in word:
if letter in puctuations:
letter.replace(punctuations, "")
if word not in result.keys():
result[word] = 0
else:
result[word] +=1
#wordcloud
cloud = wordcloud.WordCloud()
cloud.generate_from_frequencies()
return cloud.to_array()
#wordcloud
cloud = wordcloud.WordCloud()
cloud.generate_from_frequencies()
return cloud.to_array()
# Display your wordcloud image
myimage = calculate_frequencies(file_contents)
plt.imshow(myimage, interpolation = 'nearest')
plt.axis('off')
plt.show()
After executing i am getting an error:
---------------------------------------------------------------------------TypeError
Traceback (most recent call
last)<ipython-input-75-fd0f708f372c> in <module> 1 # Display your
wordcloud image 2 ----> 3 myimage =
calculate_frequencies(file_contents) 4 plt.imshow(myimage,
interpolation = 'nearest') 5 plt.axis('off')
<ipython-input-74-960d677d987a> in
calculate_frequencies(file_contents) 27 #wordcloud 28
cloud = wordcloud.WordCloud()---> 29
cloud.generate_from_frequencies() 30 return cloud.to_array()
TypeError: generate_from_frequencies() missing 1 required positional
argument: 'frequencies'
Thanks in advance, :)
More information about the Tutor
mailing list