Created
April 27, 2017 18:43
-
-
Save binary-signal/d2080c58c5a694511e1bc51d56e1da66 to your computer and use it in GitHub Desktop.
rotate a node in a list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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