Count Words in String

 String Count


import re


def check_status(*args):

   str = 'catinahat and cat and cat'

   substring = 'cat|hat'

   get_value = re.findall(substring, str)

   counts = list(get_value.count(arg) for arg in args)

   return counts


#matches = check_status()

cat_counts = 'cat'

hat_counts = 'hat'


result = check_status(cat_counts, hat_counts)


print(result)

No comments

Powered by Blogger.