Skip to content

Instantly share code, notes, and snippets.

@binary-signal
Created April 27, 2017 18:43
Show Gist options
  • Save binary-signal/d2080c58c5a694511e1bc51d56e1da66 to your computer and use it in GitHub Desktop.
Save binary-signal/d2080c58c5a694511e1bc51d56e1da66 to your computer and use it in GitHub Desktop.
rotate a node in a list
def rotate(path, j):
"""
rotate list of vertices at vertex j
:param path: a list of nodes
:param j: vertex to perform rotation at
:return: rotated path
"""
if j in path:
i = path.index(j)
newpath = path[:i + 1]
return newpath + list(reversed((path[i + 1:])))
else:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment