Python: Removes the given string from the list if the string includes some keyword v.2

advertisements

I am trying to make a code to exclude certain keywords in the string from the list of strings. This morning with help from stackoverflow, I could add the code that can exclude certain strings which include the certain keywords. Python: Remove the certain string from list if string includes certain keyword

However, when I change the data set, it does not work.

# -*- coding: utf-8 -*-

import nltk, json, os, csv, matplotlib, pylab, re
from matplotlib import *
from nltk import *
from pylab import *
from re import *

'Start with empty list'
tweets=[]
tweetsF=[]

for line in open('apple.json'):
    try:
        tweets.append(json.loads(line))
    except:
        pass

keywordFilter=['pie','juice','cinnamon']

for tweet in tweets:
    for key, value in tweet.items():
        if key=='text':
            tweetsF.append(value)

print(tweetsF[:50])
original_list=tweetsF[:50]

tweetsFBK=[str for str in original_list if not any(word in str for word in keywordFilter)]
print (tweetsFBK)

From this morning code to above code, I only changed tweetsF part which returns the list of strings from the data source. However, I think it isn't really a matter because it is a list of strings like this morning question.

Do you have any idea why excluding part does not return any value (i.e returns 0). ?

[EDITED]

original_list=['RT @haussera: Access to Apple Pay customer data, no, but another way? everybody wins - MarketWatch http://t.co/Fm3LE2iTkY', "Landed in the US, tired w horrible migrane. The only thing helping- Connie's new song on repeat. #SoGood #Nashville https://t.co/AscR4VUkMP", 'I wish jacob would be my cinnamon apple', "I've collected 9,112 gold coins! http://t.co/T62o8NoP09 #iphone, #iphonegames, #gameinsight", 'HAHAHA THEY USED THE SAME ARTICLE AS INDEPENDENT http://t.co/mC7nfnhqSw', '@hot1079atl Let me know what you think of the new single "Mirage "\nhttps://t.co/k8DJ7oxkyg', 'RT @SWNProductions: Hey All so we have a new iTunes listing due to our old one getting messed up please resubscribe via the following https…', 'Shawty go them apple bottoms jeans and the boots with the furrrr with furrrr the whole club is looking at her