How Alike Are Two Tag Lists?

Python for AIMedium+10 XP+10

How Alike Are Two Tag Lists?

A photo site suggests similar photos by comparing their tags. It scores two tag lists like this:

score = (number of different tags they share) ÷ (number of different tags used by either)

So 1.0 means identical tags, and 0.0 means nothing in common.

Task: write similarity(tags_a, tags_b). Return the score rounded to 2 decimal places.

  • Repeats inside one list don't count twice.
  • If both lists are empty, return 0.0.

Examples

tags_a = ["cat", "cute", "sofa"]
tags_b = ["cat", "sofa", "sleep", "cat"]
returns 0.5
tags_a = []
tags_b = []
returns 0.0

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run