def dependents(tokens, head_index):
 head_to_deps = {}
 for (i, token) in enumerate(tokens):
  head = token['dependencyEdge']['headTokenIndex']
  if (i != head):
   head_to_deps.setdefault(head, []).append(i)
 return head_to_deps.get(head_index, ())

def dependents ( tokens , head_index ) : head_to_deps = { } for ( i , token ) in enumerate ( tokens ) : head = token [ 'dependencyEdge' ] [ 'headTokenIndex' ] if ( i != head ) : head_to_deps . setdefault ( head , [ ] ) . append ( i ) return head_to_deps . get ( head_index , ( ) )
returns an ordered list of the token indices of the dependents for the given head .