Skip to content

Instantly share code, notes, and snippets.

@bombsimon
Created December 11, 2019 14:51
Show Gist options
  • Save bombsimon/bd92fe84b9b6ef4a27affc976265bbd1 to your computer and use it in GitHub Desktop.
Save bombsimon/bd92fe84b9b6ef4a27affc976265bbd1 to your computer and use it in GitHub Desktop.
Get the outer frame coordiantes from a 2D array
def outer_coordiantes(arr):
"""
Get the outer most coordiantes for a 2D array, starting at 0,0.
>>> outer_coordiantes([[0,0,0],[0,0,0][0,0,0]])
[(0,0), (0,1), (0,2), (1,2), (2,2), (2,1), (2,0), (1,0)]
"""
# Top row
frame_coordiantes = [(0, x) for x in range(len(arr[0]) - 1)]
# Right row
frame_coordiantes += [(x, len(arr) - 1) for x in range(len(arr) - 1)]
# Bottom row
frame_coordiantes += [
(len(arr[0]) - 1, x) for x in reversed(range(len(arr[0])))
]
# Left row
frame_coordiantes += [(x, 0) for x in reversed(range(1, len(arr) - 1))]
return frame_coordiantes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment