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 possi
If we want to do this without itertools:
def interleave(l1, l2, default=None):
max_l = max(len(l1), len(l2))
data = map(lambda x: x + [default] * (max_l - len(x)), [l1,l2])
return [data[i%2][i/2] for i in xrange(2*max_l)]
Ahh, missed the equally spaced part. This was for some reason marked as duplicate with a question that didn't require equally spaced in the presence of differing list lengths.