Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
spiral matrix
!#/usr/bin/python
import sys
file = open(sys.argv[1])
lst = []
for line in file:
lst.append(line.strip().split())
def spiral(matrix):
return list(matrix[0]) + spiral(list(reversed(zip(*matrix[1:])))) if matrix else []
print " ".join(spiral(lst))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.