vendredi 8 juin 2018

How to count the top 150 words and remove common words from 2 lists?

This code below is to find out the top 150 words which appeared the most in 2 strings.

positivewords = re.findall(r'\w+',positive) positivetop150words=Counter(positivewords).most_common(150) sorted(positivetop150words)

negativewords = re.findall(r'\w+',negative) negativetop150words=Counter(negativewords).most_common(150) sorted(negativetop150words)

This code below is to remove the common words which appeared in the 2 strings. def new(negativetop150words,positivetop150words): for i in negativetop150words[:]: if i in positivetop150words: negativetop150words.remove(i) positivetop150words.remove(i) print(i)

However, there is no output for print(i). what is wrong?

Aucun commentaire:

Enregistrer un commentaire