code: def assortativity_attributes(user):
      
  
      matrix = matrix_undirected_unweighted(user)
  
      neighbors = [k for k in user.network.keys() if k != user.name]
      neighbors_attrbs = {}
      for i, u_name in enumerate(matrix_index(user)):
          correspondent = user.network.get(u_name, None)
          if correspondent is None or u_name == user.name or matrix[0][i] == 0:
              continue
  
          if correspondent.has_attributes:
              neighbors_attrbs[correspondent.name] = correspondent.attributes
  
      assortativity = {}
      for a in user.attributes:
          total = sum(1 for n in neighbors if n in neighbors_attrbs and user.attributes[a] == neighbors_attrbs[n][a])
          den = sum(1 for n in neighbors if n in neighbors_attrbs)
          assortativity[a] = total / den if den != 0 else None
  
      return assortativity
docs: Computes the assortativity of the nominal attributes.
  
      This indicator measures the homophily of the current user with his
      correspondants, for each attributes. It returns a value between 0
      (no assortativity) and 1 (all the contacts share the same value):
      the percentage of contacts sharing the same value.