Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. from toGraphWorker import graph
  2.  
  3. Colors = [1, 2, 3, 4]
  4. Max_pow = 0
  5. Min_pow = 0
  6.  
  7.  
  8. def sorter(dict):
  9.     new_dict = {}
  10.     pows = []
  11.     for i in dict:
  12.         pows.append(len(dict[i]))
  13.     pows.sort(reverse=True)
  14.     global Max_pow
  15.     Max_pow = pows[0]
  16.     global Min_pow
  17.     Min_pow = pows[len(pows) - 1]
  18.     for i in pows:
  19.         for j in dict:
  20.             if len(dict[j]) == i:
  21.                 new_dict[j] = []
  22.                 new_dict[j].append(dict[j])
  23.     return new_dict
  24.  
  25.  
  26. def solving(dict_of_country):
  27.     color = 0
  28.     countries_with_colors = {}
  29.     current_countries = []
  30.     name = ''
  31.     name_of_last = ''
  32.     pow_of_country = Max_pow
  33.     for c in range(len(dict_of_country)):
  34.         countries_with_colors[c] = set()
  35.     for i in dict_of_country:
  36.         countries_with_colors[0].add(i)
  37.         if len(dict_of_country[i][0]) == Max_pow:
  38.             color = 1
  39.             if len(countries_with_colors[color])==0:
  40.                 countries_with_colors[color].add(i)
  41.         elif len(dict_of_country[i][0]) == Min_pow:
  42.             name_of_last = i
  43.     print(countries_with_colors[0])
  44.     while len(countries_with_colors[0]) != 0:
  45.         for i in dict_of_country:
  46.             if i in countries_with_colors[0] and countries_with_colors[color].isdisjoint(dict_of_country[i][0]):
  47.                     countries_with_colors[color].add(i)
  48.         color += 1
  49.  
  50.     return countries_with_colors
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement