# Function to reorder vertices?

**URL:** <https://igraph.discourse.group/t/function-to-reorder-vertices/384>\
**Category:** Usage\
**Tags:** C, Python, R\
**Created:** [29 July 2020 06:53 UTC](https://igraph.discourse.group/t/function-to-reorder-vertices/384 "2020-07-29T06:53:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [29 July 2020 06:53 UTC](https://igraph.discourse.group/t/function-to-reorder-vertices/384/1 "2020-07-29T06:53:25Z")

</div>

Is there a function that re-orders vertices while preserving vertex and edge attributes? I am primarily interested in the Python interface, but if there is a function, I’d also like to know its name in C and R.

I could not find one, but this seems like a fairly fundamental operation, so perhaps I missed it.

Example to clarify:

Given a directed graph with vertices `0, 1, 2` and one edge `1 -> 2`, permute/rename the vertices as

```auto
0 -> 2
1 -> 1
2 -> 0

```

to obtain the graph with the edge `1 -> 0`.

---

<div class="post-metadata">

**Author:** ![tamas](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/tamas/32/1261_2.png) [@tamas](https://igraph.discourse.group/u/tamas)\
**Post date:** [29 July 2020 09:44 UTC](https://igraph.discourse.group/t/function-to-reorder-vertices/384/2 "2020-07-29T09:44:29Z")

</div>

It is called [`igraph_permute_vertices()`](https://igraph.org/c/doc/igraph-Isomorphism.html#igraph_permute_vertices). I think it can also be (ab)used to calculate induced subgraphs or to duplicate vertices and the edges incident on them.

Actually, we could probably just delegate the implementation of `igraph_induced_subgraph()` to this function if the user asked to create the new graph from scratch.

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [29 July 2020 10:15 UTC](https://igraph.discourse.group/t/function-to-reorder-vertices/384/3 "2020-07-29T10:15:03Z")

</div>

Thanks!

In R: [https://igraph.org/r/doc/permute.html](https://igraph.org/r/doc/permute.html)

In Python: [https://igraph.org/python/doc/igraph.GraphBase-class.html#permute\_vertices](https://igraph.org/python/doc/igraph.GraphBase-class.html#permute_vertices)

In hindsight, it would have been obvious to search for “permute” (I even used that word in the question) but somehow I didn’t …
