Shared tags between two campaigns
Python data engineering interview problem. Difficulty: beginner. Pattern: Dictionaries. About 10 minutes. Free to practice.
Two marketing campaigns each carry a list of tags. The growth team wants the tags that both campaigns already use so they do not invent a third spelling of the same theme.
Two marketing campaigns use tags like sale and new. The team wants to see which tags both campaigns share. Return the tags that appear in both lists, with no repeats, sorted alphabetically. Write shared_tags(a, b). For ['a','b','c'] and ['b','c','d'], the shared tags are ['b','c']. For ['a'] and ['b'] nothing is shared, so the answer is []. The starter file already has the function name and its print lines. Keep them and fill in the body.
Requirements
- Return only tags that are in both lists.
- Each tag appears once in the result.
- Sort the result alphabetically.
Constraints
- Both inputs are lists of strings and can be empty.
- The result is a list, not a set.
Examples
Input: shared_tags(['a', 'b', 'c'], ['b', 'c', 'd']) Output: ['b', 'c'] This input follows the stated rules and produces this output.
Topics: lakebench, python, sets.
More Python interview questions · All interview problems · Learn data engineering
Shared tags between two campaigns
Interview-style drill: Given two lists of campaign tags, return the tags that appear in both.
Return the tags that appear in both input lists.