f = file("largefile.txt") for line in f: try: tweet_time = line.split(',',3)[2].split()[0] tweet = line.split(',',3)[-1] for topic in topics: topic_items = topic.split() isContain = True for item in topic_items: if item not in tweet: isContain = False break if isContain: pass except: continue f.close()