def ndependents(dependencies, dependents):
 result = dict()
 num_needed = dict(((k, len(v)) for (k, v) in dependents.items()))
 current = set((k for (k, v) in num_needed.items() if (v == 0)))
 while current:
  key = current.pop()
  result[key] = (1 + sum((result[parent] for parent in dependents[key])))
  for child in dependencies[key]:
   num_needed[child] -= 1
   if (num_needed[child] == 0):
    current.add(child)
 return result

def ndependents ( dependencies , dependents ) : result = dict ( ) num_needed = dict ( ( ( k , len ( v ) ) for ( k , v ) in dependents . items ( ) ) ) current = set ( ( k for ( k , v ) in num_needed . items ( ) if ( v == 0 ) ) ) while current : key = current . pop ( ) result [ key ] = ( 1 + sum ( ( result [ parent ] for parent in dependents [ key ] ) ) ) for child in dependencies [ key ] : num_needed [ child ] -= 1 if ( num_needed [ child ] == 0 ) : current . add ( child ) return result
number of total data elements that depend on key for each key we return the number of data that can only be run after this key is run .