IntermediateChallenge 23 of 34

Spiral order

Write spiral(matrix) that returns the elements of a 2-D in clockwise spiral order, starting from the top-left corner.

Examples
spiral([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) → [1, 2, 3, 6, 9, 8, 7, 4, 5]
Exercise

Spiral order

4 checks
def spiral(matrix):
    ...


print(spiral([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))
 
Python (loads on first run)Ctrl+Enter runs
Output
Press Run to try your code, then Check answer to grade it.