Created
October 18, 2016 15:37
-
-
Save kkroesch/29ac39d9b891f10786e838c5e24aabb4 to your computer and use it in GitHub Desktop.
A primitive search for keywords in a text.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
from collections import Counter | |
george_takei_tweet = "When the media gave him millions in free air time, Trump loved them. Now when they do their job and ask questions, it's a global conspiracy." | |
tweet = george_takei_tweet.lower() | |
tweet = ''.join(ch for ch in tweet if ch not in set(string.punctuation)) | |
contains = Counter(tweet.split(' ')) | |
eval("contains['trump'] and contains['conspiracy']") | |
# ==> 1 | |
eval("contains['trump'] and not contains['conspiracy']") | |
# ==> False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment