def strategy_smallest_last(G, colors):
 H = G.copy(with_data=False)
 result = deque()
 degrees = defaultdict(set)
 lbound = float('inf')
 for (node, d) in H.degree():
  degrees[d].add(node)
  lbound = min(lbound, d)
 def find_min_degree():
  return next((d for d in itertools.count(lbound) if (d in degrees)))
 for _ in G:
  min_degree = find_min_degree()
  u = degrees[min_degree].pop()
  if (not degrees[min_degree]):
   del degrees[min_degree]
  result.appendleft(u)
  for v in H[u]:
   degree = H.degree(v)
   degrees[degree].remove(v)
   if (not degrees[degree]):
    del degrees[degree]
   degrees[(degree - 1)].add(v)
  H.remove_node(u)
  lbound = (min_degree - 1)
 return result

def strategy_smallest_last ( G , colors ) : H = G . copy ( with_data = False ) result = deque ( ) degrees = defaultdict ( set ) lbound = float ( 'inf' ) for ( node , d ) in H . degree ( ) : degrees [ d ] . add ( node ) lbound = min ( lbound , d ) def find_min_degree ( ) : return next ( ( d for d in itertools . count ( lbound ) if ( d in degrees ) ) ) for _ in G : min_degree = find_min_degree ( ) u = degrees [ min_degree ] . pop ( ) if ( not degrees [ min_degree ] ) : del degrees [ min_degree ] result . appendleft ( u ) for v in H [ u ] : degree = H . degree ( v ) degrees [ degree ] . remove ( v ) if ( not degrees [ degree ] ) : del degrees [ degree ] degrees [ ( degree - 1 ) ] . add ( v ) H . remove_node ( u ) lbound = ( min_degree - 1 ) return result
returns a deque of the nodes of g .