def permute_vector(rev_order, membership):
    """
	Rearrange community membership vector according to permutation

	Used to realign community vector output after node permutation.

	:param rev_order: new indices of each nodes
	:param membership: community membership vector to be rearranged
	:return: rearranged membership vector.
	"""
    new_member = [(-1) for i in range(len(rev_order))]
    for i, val in enumerate(rev_order):
        new_member[val] = membership[i]
    assert -1 not in new_member
    return new_member
