Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
itertools to the rescue solution in Clear category for Zigzag Array by ssk8
from typing import List
from itertools import zip_longest
def create_zigzag(rows: int, cols: int, start: int = 1) -> List[List[int]]:
if cols:
groups = zip_longest(*[iter(range(start, start + rows*cols))] * cols)
return [[*x][::(1 - 2 * (i % 2))] for i, x in enumerate(groups)]
else:
return [[] for _ in range(rows)]
Nov. 9, 2018
Comments: