I want to merge two lists in Python, with the lists being of different lengths, so that the elements of the shorter list are as equally spaced within the final list as possible.
i.e. I want:
l1 = [1, 2, 3, 4]
l2 = ['a', 'b']
output = [1, 'a', 2, 3, 'b', 4]
It needs to be able to function with lists that aren't exact multiples too, so it could take:
l1 = [1, 2, 3, 4, 5]
l2 = ['a', 'b', 'c']
and produce [1, 'a', 2, 'b', 3, 'c', 4, 5]
or similar.
It needs to preserve the ordering of both lists.
I can see how to do this by a long-winded brute force method but since Python seems to have a vast array of excellent tools to do all sorts of clever things which I don't know about (yet), I wondered whether there's anything more elegant I can use?
If you want regular interleaving (equal-spaced), see How to interleave two lists of different length?.