#!/usr/bin/env python3
def conflicting(a, b):
return any([not a.isdisjoint(i) for i in b])
def partition(industry_dict):
"industry_dict = { id: set(economies) }"
candidates = list(map(lambda x: x[0], sorted([(ind, len(ecos)) for ind, ecos in industry_dict.items()], key=lambda x: x[1])))
result = []
while candidates:
i=0
part = set()
result.append(part)
while i < len(candidates):
if conflicting(industry_dict[candidates[i]], [industry_dict[ind] for ind in part]):
i+=1
else:
part.add(candidates[i])
del candidates[i]
return result