Loading

Paste #pe7t5aq3f

  1. #!/usr/bin/env python3
  2.  
  3. def conflicting(a, b):
  4.     return any([not a.isdisjoint(i) for i in b])
  5.  
  6. def partition(industry_dict):
  7.     "industry_dict = { id: set(economies) }"
  8.     candidates = list(map(lambda x: x[0], sorted([(ind, len(ecos)) for ind, ecos in industry_dict.items()], key=lambda x: x[1])))
  9.     result = []
  10.     while candidates:
  11.         i=0
  12.         part = set()
  13.         result.append(part)
  14.         while i < len(candidates):
  15.             if conflicting(industry_dict[candidates[i]], [industry_dict[ind] for ind in part]):
  16.                 i+=1
  17.             else:
  18.                 part.add(candidates[i])
  19.                 del candidates[i]
  20.     return result

Comments