Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TypeError: 'zip' object is not subscriptable
- from future_builtins import zip
- def find_spiral_2(matrix):
- "Return list of elements of matrix in clockwise spiral order."
- h, w = len(matrix), len(matrix[0]) # Height and width of remainder
- i, j = 0, -1 # Current position in spiral
- di, dj = 0, 1 # Current direction of movement
- spiral = []
- while h > 0:
- # Output top row
- for _ in range(w):
- i += di
- j += dj
- spiral.append(matrix[i][j])
- # Remove top row and rotate quarter-turn
- h, w = w, h - 1
- di, dj = dj, -di
- return spiral
- def find_spiral_2(matrix):
- "Generate elements of matrix in clockwise spiral order."
- h, w = len(matrix), len(matrix[0]) # Height and width of remainder
- i, j = 0, -1 # Current position in spiral
- di, dj = 0, 1 # Current direction of movement
- while h > 0:
- # Output top row
- for _ in range(w):
- i += di
- j += dj
- yield matrix[i][j]
- # Remove top row and rotate quarter-turn
- h, w = w, h - 1
- di, dj = dj, -di
Add Comment
Please, Sign In to add comment