Given a list of sorted domains, how would you minimize the output of URLs by uniting sub-domains and listing sibling domains under their common ancestor?
Implement minimize_domains(domains), returning a lexicographically sorted list of compact domain patterns. Merge sibling labels only when their descendant structures are identical, suppress descendants when an ancestor domain is present, and do not merge top-level suffixes such as .com and .net.
For example, ["api.example.com", "cdn.example.com"] becomes ["{api,cdn}.example.com"], while ["a.example.com", "b.example.com", "a.example.net", "b.example.net"] becomes ["{a,b}.example.com", "{a,b}.example.net"]. Domains contain lowercase labels separated by periods.
def minimize_domains(domains):