[Solved] Using zip_longest on unequal lists but repeat the last entry instead of returning None


itertools.izip_longest takes an optional fillvalue argument that provides the value that is used after the shorter list has been exhausted. fillvalue defaults to None, giving the behaviour you show in your question, but you can specify a different value to get the behaviour you want:

    fill = a[-1] if (len(a) < len(b)) else b[-1]
    for i in itertools.izip_longest(a, b, fillvalue=fill):
        print i

(Obviously if the same list is always the shorter one then choosing the fill character is even easier.)

0

solved Using zip_longest on unequal lists but repeat the last entry instead of returning None