OnThaRise
OnThaRise

Reputation: 127

Word Frequency Analysis - TypeError: '>=' not supported between instances of 'list' and 'int'

I am running a code on Jupyter Notebook regarding Word Frequency Analysis using this website: http://theautomatic.net/2017/10/12/word-frequency-analysis/ ... As I get to the end of the process, I get an error when running that says the following:

TypeError: '>=' not supported between instances of 'list' and 'int'.

Basically, I have to filter out articles that don't mention Netflix at least 3 times.

article_to_freq = {article:freq for article, freq in 
                   article_to_freq.items() if freq >= 3}

The error seem to happen on the 2nd line of this code: article_to_freq.items() if freq >= 3}

As mentioned before, I keep getting:

TypeError: '>=' not supported between instances of 'list' and 'int'

Any help would be greatly appreciated, thank you!

Upvotes: 2

Views: 375

Answers (1)

Diana Neels
Diana Neels

Reputation: 46

I assume the problem would be that you are comparing "freq" which is a list(array) to 3 which is an integer(number). The solution is to use len(freq) which would compare the length of the array with the number 3 as showed in the example below:

#random example of the list
freq =[1,2,3,4,5,6,7]

#you use len() to get the length of the array
if len(freq) >= 3:
    print(freq) #or do what ever it is you want to do with it

Hope this helped

Upvotes: 3

Related Questions