Interview Query

Tag Counter

2
Have you seen this question before?

You are asked to develop a simple tag counter that will look for the occurrence of certain words or phrases in a piece of text.

You are given a paragraph as a string and a list of tag groups as a list of lists of strings. Write a tag_counter function that returns a list of integers with the number of times each tag in the tag group was used in the text.

Note: Your function should be case-insensitive with regards to the tag groups.

Example:

Input:

tag_groups = [
    ['data scientist', 'data analyst'], 
    ['data engineer', 'data wrangler'], 
    ['machine learning engineer'], 
    ['data' , 'engineer']]
text = "Today, with the advent of data science, different roles have emerged in the industry. Job postings are abundant of many names such as data scientist, data engineer, data wrangler, deep learning specialist, and machine learning specialist to name a few."

Output:

def tag_counter(tag_groups,text) -> [1, 2, 0, 5]
Next question: Move Zeros Back
.....
Python 3.9.6
Loading editor
Use Shift + Enter to run code