fork download
  1. from collections import Counter
  2.  
  3. def contains(sentence, phrase):
  4. return all(sentence[word] >= phrase[word] for word in phrase)
  5.  
  6. sent = ["Strings are an array of characters",
  7. "Sentences are an array of words"]
  8. ph = ["an array of", "sentences are strings"]
  9.  
  10. sent = [Counter(word.lower() for word in sentence.split()) for sentence in sent]
  11. ph = [Counter(word.lower() for word in sentence.split()) for sentence in ph]
  12.  
  13. print(sent, ph)
  14.  
  15. for i, phrase in enumerate(ph, start=1):
  16. print("Phrase{}:".format(i))
Success #stdin #stdout 0.01s 27712KB
stdin
Standard input is empty
stdout
[Counter({'are': 1, 'of': 1, 'strings': 1, 'characters': 1, 'array': 1, 'an': 1}), Counter({'words': 1, 'are': 1, 'of': 1, 'sentences': 1, 'array': 1, 'an': 1})] [Counter({'of': 1, 'array': 1, 'an': 1}), Counter({'sentences': 1, 'are': 1, 'strings': 1})]
Phrase1:
Phrase2: