import numbers


def normalize_edgeweight(network):
    """
    Normalizes the edge weights to be between 0 and 1.
    :param network: networkx.Graph
            Graph with unnormalized weight attributes on the edges
    :return:
        network: networkx.Graph
         Graph with normalized weight attributes on the edges
    """
    if len(network.edges()) == 0:
        return network
    e = list(network.edges())[0]
    w = network[e[0]][e[1]]['weight']

    if isinstance(w, numbers.Number):
        w_max = max(network[e[0]][e[1]]['weight'] for e in network.edges())
        for u, v, d in network.edges(data=True):
            d['weight'] /= w_max
    elif type(w) is dict:
        w_max = max(max(network[e[0]][e[1]]['weight'].values()) for e in network.edges())
        for u, v, d in network.edges(data=True):
            for k in d['weight'].keys():
                d['weight'][k] /= w_max
    else:
        return None
    return network