Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # DOCUMENTS
- doc1 = "My sister likes to have sugar, but not my father."
- doc2 = "Doctors suggest that driving may cause increased stress."
- documents = [doc1, doc2]
- # DICTIONARY
- dictionary = ["doctors", "sister", "like"]
- # CHECK DOCUMENT WORDS WITHIN DICTIONARY
- for word in dictionary:
- for doc in documents:
- if word in doc:
- print "nnnWord:",
- print word,
- print "in document:",
- print doc
- doc1 = "My sister likes to have sugar, but not my father.".split()
- doc2 = "Doctors suggest that driving may cause increased stress.".split()
- import string
- doc1 = "My sister likes to have sugar, but not my father.".translate(None, string.punctuation).split()
- doc2 = "Doctors suggest that driving may cause increased stress.".translate(None, string.punctuation).split()
- documents = map(set, [doc1, doc2])
- # DICTIONARY
- dictionary = ["doctors", "sister", "like"]
- for word in dictionary:
- for doc in documents:
- if word in doc:
- print "nnnWord:",
- print word,
- print "in document:",
- print doc
- Word: sister in document: set(['sister', 'my', 'father', 'but', 'sugar', 'to', 'likes', 'have', 'not', 'My'])
- import string
- def get_words(text):
- return set(text.translate(None, string.punctuation).split())
- if __name__ == "__main__":
- documents = ["My sister likes to have sugar, but not my father.",
- "Doctors suggest that driving may cause increased stress."]
- words_in_documents = map(get_words, documents)
- for word in ["doctors", "sister", "like"]:
- for doc, words in zip(documents, words_in_documents):
- if word in words:
- print "nnnWord: {} in document: {}".format(word, doc)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement