def richclub(graph, fraction=0.1, highest=True, scores=None, indices_only=False):
    # from http://igraph.wikidot.com/python-recipes#toc6
    """Extracts the "rich club" of the given graph, i.e. the subgraph spanned
    between vertices having the top X% of some score.

    Scores are given by the vertex degrees by default.

    @param graph:    the graph to work on
    @param fraction: the fraction of vertices to extract; must be between 0 and 1.
    @param highest:  whether to extract the subgraph spanned by the highest or
                     lowest scores.
    @param scores:   the scores themselves. C{None} uses the vertex degrees.
    @param indices_only: whether to return the vertex indices only (and not the
                         subgraph)
    """

    if scores is None:
        scores = graph.degree ( )
    n = int (round (graph.vcount ( ) * fraction))
    indices = range (graph.vcount ( ))
    indices = sorted (indices, key=scores.__getitem__)
    # indices.sort (key=scores.__getitem__)
    # indices = sorted (zip (graph.vs, graph.degree (mode=ALL)), reverse=True)#get_top_n_for_list (graph, graph.degree (mode=ALL), n)

    if highest:
        indices = indices[-n:]
    else:
        indices = indices[:n]

    if indices_only:
        return indices

    return graph.subgraph (indices)