DeaD_EyE

posivite_negative_list

Jul 28th, 2020 (edited)
997
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sentences = [
  2.     "I have a cat",
  3.     "I want to have chicken",
  4.     "Horse in the barn",
  5.     "I like cow",
  6.     "Dog plays with cat",
  7.     "Rabbit likes carrot",
  8.     "this pig is big",
  9.     "Mouse in the house",
  10. ]
  11.  
  12. words = ["cat", "dog", "pig", "chicken"]
  13. words = {w.strip().lower() for w in words}
  14. # set comprehension
  15. # https://python-reference.readthedocs.io/en/latest/docs/comprehensions/set_comprehension.html
  16.  
  17.  
  18. def sentence_checker(words, sentence):
  19.     sentence = set(sentence.lower().split())
  20.     return not words.isdisjoint(sentence)
  21.  
  22.  
  23. def main():
  24.     positive_list = []
  25.     negative_list = []
  26.     for sentence in sentences:
  27.         if sentence_checker(words, sentence):
  28.             positive_list.append(sentence)
  29.         else:
  30.             negative_list.append(sentence)
  31.     return positive_list, negative_list
  32.  
  33.  
  34. pos, neg = main()
  35. print(pos)
  36. print(neg)
RAW Paste Data