
Normalize hashtags
easyNormalize hashtags
Pinterest Python Interview Question
Pinterest groups pins by the tags creators type in, but creators type the same tag in different ways, such as "#Travel" and " travel ".
Write a function normalize_tags(tags) that takes a list of tags and returns a list of clean tags. To clean a tag, remove spaces at both ends, then remove any # signs at the start, then make it lowercase. Leave out tags that end up empty, and keep only the first copy of each clean tag, in the order they first appear.
Asked of
- Data Engineer
- Data Scientist
- Analytics Engineer
- ML Engineer
- AI Engineer
Example 1
Input
normalize_tags(["#Travel", "food", " travel ", "#DIY"])
Output
["travel", "food", "diy"]
Explanation
In the first example, "#Travel" becomes "travel" and "food" stays "food". The third tag also becomes "travel", which is already in the list, so it is left out. "#DIY" becomes "diy".
Submit also runs 4 hidden test cases that check edge cases.
Company
Pinterest
Difficulty
easy
Topic
strings
Language
Python
Your code
Loading Python in the background. You can start writing.