Safe Tag Manager

Easy ⏱ 8 min 73% acceptance ★★★★★ 4.5
Implement apply_tag_ops(tags, ops) where tags is a set of strings and ops is a list of (action, tag) tuples with action "add" or "remove". Removing a tag that is not present must not raise an error. Return the final set.

Examples

Example 1
Input
apply_tag_ops({'new'}, [('add', 'sale'), ('remove', 'old'), ('remove', 'new')])
Output
{'sale'}
Explanation

'old' is absent but removing it is a silent no-op.

Constraints

  • Never raise KeyError for a missing tag.
  • Mutate and return the same set.

Topics

Setsadd/discard

Companies

AtlassianZomato

Hints

Hint 1

set.discard() removes without raising; set.remove() raises.

Hint 2

Loop over the ops and dispatch on the action string.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.