def _izip_longest(*args, **kwds):
 fillvalue = kwds.get('fillvalue')
 def sentinel(counter=([fillvalue] * (len(args) - 1)).pop):
  (yield counter())
 fillers = itertools.repeat(fillvalue)
 iters = [itertools.chain(it, sentinel(), fillers) for it in args]
 try:
  for tup in itertools.izip(*iters):
   (yield tup)
 except IndexError:
  pass

def _izip_longest ( * args , ** kwds ) : fillvalue = kwds . get ( 'fillvalue' ) def sentinel ( counter = ( [ fillvalue ] * ( len ( args ) - 1 ) ) . pop ) : ( yield counter ( ) ) fillers = itertools . repeat ( fillvalue ) iters = [ itertools . chain ( it , sentinel ( ) , fillers ) for it in args ] try : for tup in itertools . izip ( * iters ) : ( yield tup ) except IndexError : pass
taken from python docs URL#itertools .