Join sets quickly with union-find
Union-find tracks which items belong together, such as connected computers or merged accounts. Each item points to a parent; following parents reaches a root that names the whole set.
parent = {x: x for x in "abc"}
parent["b"] = "a" # b joins a's setThink before coding
Path compression makes every node on a find path point straight at the root, so later finds are almost instant. Union just points one root at the other. Two items are connected when their roots are equal. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
Your task
Write a UnionFind class built from an iterable of items, with find(x), union(a, b) and connected(a, b). Use path compression in find.
The explanation opens here once every check passes.