def get_weights(G):
    """
    Given a graph G, returns a list of weights. If the graph is unweighted,
    returns a list of 1s the same length as the number of edges. 
    """
    try:
        # asssumes weight as an attribute name means graph is weighted.
        weights = G.es['weight']
    except KeyError:
        #unweighted means all weights are 1.
        weights = [1 for e in G.es]
    return weights