def distance_between_categories(features):
    """
    Calculates the distance between all the categories for every feature.
    
    Parameters
    ----------
    features : dictionary
        a dictionary of features with keys as feature name and values as objects of
        feature class
     
    Returns
    -------
    features : dictionary
        a dictionary of features with keys as feature name and values as objects of
        feature class with updated distance values
    """
    for feat in features:
        for i in features[feat].category_order.keys():
            features[feat].distances[features[feat].category_order[i]] = dict()
    for feat in features:
        for i in features[feat].category_order.keys():
            features[feat].distances[features[feat].category_order[i]][
                features[feat].category_order[i]] = 0
            if features[feat].feat_type == 'ordinal':
                for j in range(i + 1, features[feat].num_cat):
                    prev = features[feat].distances[features[feat].
                        category_order[i]][features[feat].category_order[j - 1]
                        ]
                    curr = prev + features[feat].weight * features[feat
                        ].categories[features[feat].category_order[j]].entropy
                    features[feat].distances[features[feat].category_order[i]][
                        features[feat].category_order[j]] = curr
                    features[feat].distances[features[feat].category_order[j]][
                        features[feat].category_order[i]] = curr
            else:
                for j in range(i + 1, features[feat].num_cat):
                    curr = features[feat].weight * (features[feat].
                        categories[features[feat].category_order[j]].
                        entropy + features[feat].categories[features[feat].
                        category_order[i]].entropy)
                    features[feat].distances[features[feat].category_order[i]][
                        features[feat].category_order[j]] = curr
                    features[feat].distances[features[feat].category_order[j]][
                        features[feat].category_order[i]] = curr
    return features
