Counter-Simple
Sat 17 May 2025
title: "Counter Simple" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false
from collections import Counter
a = Counter("Hello there, How are you")
a
Counter({' ': 4,
',': 1,
'H': 2,
'a': 1,
'e': 4,
'h': 1,
'l': 2,
'o': 3,
'r': 2,
't': 1,
'u': 1,
'w': 1,
'y': 1})
def isin(a, b):
return not Counter(a) - Counter(b)
isin("hel my frend", "hello my friend")
True
More:
https://stackoverflow.com/questions/56189821/how-to-check-if-a-string-is-a-substring-of-another-even-if-not-in-order
Score: 5
Category: basics