def resolve_embedded_documents(document, resource, embedded_fields):
 for field in sorted(embedded_fields, key=(lambda a: a.count('.'))):
  data_relation = field_definition(resource, field)['data_relation']
  getter = (lambda ref: embedded_document(ref, data_relation, field))
  fields_chain = field.split('.')
  last_field = fields_chain[(-1)]
  for subdocument in subdocuments(fields_chain[:(-1)], resource, document):
   if (last_field not in subdocument):
    continue
   if isinstance(subdocument[last_field], list):
    subdocument[last_field] = list(map(getter, subdocument[last_field]))
   else:
    subdocument[last_field] = getter(subdocument[last_field])

def resolve_embedded_documents ( document , resource , embedded_fields ) : for field in sorted ( embedded_fields , key = ( lambda a : a . count ( '.' ) ) ) : data_relation = field_definition ( resource , field ) [ 'data_relation' ] getter = ( lambda ref : embedded_document ( ref , data_relation , field ) ) fields_chain = field . split ( '.' ) last_field = fields_chain [ ( - 1 ) ] for subdocument in subdocuments ( fields_chain [ : ( - 1 ) ] , resource , document ) : if ( last_field not in subdocument ) : continue if isinstance ( subdocument [ last_field ] , list ) : subdocument [ last_field ] = list ( map ( getter , subdocument [ last_field ] ) ) else : subdocument [ last_field ] = getter ( subdocument [ last_field ] )
loops through the documents .