def count_communities(G, cover):
    """
    Helper for lazar_modularity.

    Returns a dict {v:count} where v is a vertex id and
    count is the number of different communities it is
    assigned to.
    """
    counts = {i.index : 0 for i in G.vs}
    for community in cover:
        for v in community:
            counts[v] += 1
    return counts