# Create an empty string title_combined = '' # Loop through all the headlines and add them to 'text_combined' for i in response_json['articles']: title_combined += i[ 'title'] + ' ' # add a space after every headline, so the first and last words are not glued together # Print the first 300 characters to screen for inspection #print(text_combined[0:300]) # In[217]: titles = title_combined.replace('\s+', ' ').replace(',', ' ').replace('.', ' ') words_t = titles.split() result = [ word for word in words_t if (word.lower() not in bad_words and len(word) > 3) ] result = ' '.join(result) wordcount = {} for word in result.split(): if word not in wordcount: wordcount[word] = 1 else: wordcount[word] += 1 for k, v, in sorted(wordcount.items(), key=lambda words: words[1], reverse=True): print(k, v)