from collections import Counter
def contains(sentence, phrase):
return all(sentence[word] >= phrase[word] for word in phrase)
sent = ["Strings are an array of characters",
"Sentences are an array of words"]
ph = ["an array of", "sentences are strings"]
sent = [Counter(word.lower() for word in sentence.split()) for sentence in sent]
ph = [Counter(word.lower() for word in sentence.split()) for sentence in ph]
print(sent, ph)
for i, phrase in enumerate(ph, start=1):
print("Phrase{}:".format(i))
ZnJvbSBjb2xsZWN0aW9ucyBpbXBvcnQgQ291bnRlcgoKZGVmIGNvbnRhaW5zKHNlbnRlbmNlLCBwaHJhc2UpOgogICAgcmV0dXJuIGFsbChzZW50ZW5jZVt3b3JkXSA+PSBwaHJhc2Vbd29yZF0gZm9yIHdvcmQgaW4gcGhyYXNlKQoKc2VudCA9IFsiU3RyaW5ncyBhcmUgYW4gYXJyYXkgb2YgY2hhcmFjdGVycyIsIAogICAgICAgICJTZW50ZW5jZXMgYXJlIGFuIGFycmF5IG9mIHdvcmRzIl0gCnBoID0gWyJhbiBhcnJheSBvZiIsICJzZW50ZW5jZXMgYXJlIHN0cmluZ3MiXQoKc2VudCA9IFtDb3VudGVyKHdvcmQubG93ZXIoKSBmb3Igd29yZCBpbiBzZW50ZW5jZS5zcGxpdCgpKSBmb3Igc2VudGVuY2UgaW4gc2VudF0KcGggICA9IFtDb3VudGVyKHdvcmQubG93ZXIoKSBmb3Igd29yZCBpbiBzZW50ZW5jZS5zcGxpdCgpKSBmb3Igc2VudGVuY2UgaW4gcGhdCgpwcmludChzZW50LCBwaCkKCmZvciBpLCBwaHJhc2UgaW4gZW51bWVyYXRlKHBoLCBzdGFydD0xKToKICAgIHByaW50KCJQaHJhc2V7fToiLmZvcm1hdChpKSk=
[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: