def sorted_dependencies(graph):
 graph = dict(((key, set(value)) for (key, value) in graph.items()))
 L = []
 S = set((parent for (parent, req) in graph.items() if (not req)))
 while S:
  n = S.pop()
  L.append(n)
  parents = [parent for (parent, req) in graph.items() if (n in req)]
  for parent in parents:
   graph[parent].remove(n)
   if (not graph[parent]):
    S.add(parent)
 nonempty = [k for (k, v) in graph.items() if v]
 if nonempty:
  raise ArgumentError(('Cyclic dependency of: %s' % ', '.join(nonempty)))
 return L

def sorted_dependencies ( graph ) : graph = dict ( ( ( key , set ( value ) ) for ( key , value ) in graph . items ( ) ) ) L = [ ] S = set ( ( parent for ( parent , req ) in graph . items ( ) if ( not req ) ) ) while S : n = S . pop ( ) L . append ( n ) parents = [ parent for ( parent , req ) in graph . items ( ) if ( n in req ) ] for parent in parents : graph [ parent ] . remove ( n ) if ( not graph [ parent ] ) : S . add ( parent ) nonempty = [ k for ( k , v ) in graph . items ( ) if v ] if nonempty : raise ArgumentError ( ( 'Cyclic dependency of: %s' % ', ' . join ( nonempty ) ) ) return L
return keys from deps ordered by dependency .