I want to split an iterable into two lists with alternating elements. Here is a working solution. But is there a simpler way to achieve the same?
def zigzag(seq):
"""Return two sequences with alternating elements from `seq`"""
x, y = [], []
p, q = x, y
for e in seq:
p.append(e)
p, q = q, p
return x, y
Sample output:
>>> zigzag('123456')
(['1', '3', '5'], ['2', '4', '6'])