Loop in a loop?

Paul Hankin paul.hankin at gmail.com
Thu Jan 17 12:25:45 EST 2008


On Jan 17, 4:38 pm, Bruno Desthuilliers <bruno.
42.desthuilli... at wtf.websiteburo.oops.com> wrote:
> Now there are very certainly smart solutions using itertools, but the
> one I cooked is way too ugly so I'll leave this to itertools masters !-)

Here's my effort:

from itertools import izip, islice, chain, repeat

def padzip(*xs, **kw):
    pad = kw.get('padding', None)
    maxlen = max(len(x) for x in xs)
    return islice(izip(*[chain(x, repeat(pad)) for x in xs]), maxlen)

--
Paul Hankin



More information about the Python-list mailing list