1
from sklearn.datasets import fetch_20newsgroups
from collections import Counter 
news = fetch_20newsgroups(subset='all')
def clean_word(word):
    return re.sub(r'[^\w\s]','',word).lower()
def word_not_in_stopwords(word):
    return word not in ENGLISH_STOP_WORDS and word and word.isalpha()


def find_top_words(news):
    cnt = Counter()
    for text in news:
        tokens_in_text = text.split()
        tokens_in_text = map(clean_word, tokens_in_text)
        tokens_in_text = filter(word_not_in_stopwords, tokens_in_text)
        cnt.update(tokens_in_text)

    return cnt.most_common(10)
%time find_top_words(news)

I get an error here:

%time find_top_words(news)
    ^
SyntaxError: invalid syntax
roganjosh
  • 12,594
  • 4
  • 29
  • 46
  • you may check this out [Hope this will help you](https://stackoverflow.com/questions/38780057/how-to-insert-current-date-time-in-vscode) – unknown Dec 28 '19 at 18:51
  • 1
    You're trying to inline IPython magic methods into your script. You should be using them in the console. I don't use VSCode so I can't help too much because I don't know what to ask about your setup. But it's almost certainly IPython you're trying to use – roganjosh Dec 28 '19 at 18:53
  • @Anonymousmerin they are trying to use [this](https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-time) – roganjosh Dec 28 '19 at 18:56

0 Answers0