3

I am trying to extract from a list of keywords just the words which are regular normal words in the English language.

Here is my code:

words = ['apple','a%32','j & quod','rectangle','house','fsdfdsoij','fdfd']
for word in words:
    if word ???: # How can I check if the words is a real word? Any module that I can use for that or a free API?
        print:
    else:
        pass

I would like to get as results only:

apple
rectangle
house
Pro Girl
  • 762
  • 7
  • 21

1 Answers1

5

First step, install nltk

Then:

import nltk
nltk.download('words')

from nltk.corpus import words

samplewords=['apple','a%32','j & quod','rectangle','house','fsdfdsoij','fdfd']

[i for i in samplewords if i in words.words()]

['apple', 'rectangle', 'house']
Billy Bonaros
  • 1,671
  • 11
  • 18