I want to split a list into 2 lists where the elements from the original list are put alternating into the new lists. Here's a simple example with the expected output.
l = ['a', 'b', 'c', 'd', 'e', 'f']
=>
['a', 'c', 'e']
['b', 'd', 'f']
I expected an existing solution for this in itertools, but couldn't find anything that fit. I also couldn't find any solution here. Eventually I went with the following solution. It works good enough, is short/readable, but is not efficient (iterating the original list twice, and using indices instead of iterators).
l1 = [l[i] for i in range(0, len(l), 2)]
l2 = [l[i] for i in range(1, len(l), 2)]
Now I'm curious. Is there an existing, generic solution that is both short AND efficient?