вместо того, чтобы строить это заново в каждом вызове.
всех сил пытаюсь понять, как работает приведенный ниже код. Это изhttp://docs.python.org/library/itertools.html#itertools.izip_longest, и является чистым python-эквивалентом итератора izip_longest. Меня особенно озадачивает функция часового, как она работает?
def izip_longest(*args, **kwds):
# izip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
fillvalue = kwds.get('fillvalue')
def sentinel(counter = ([fillvalue]*(len(args)-1)).pop):
yield counter() # yields the fillvalue, or raises IndexError
fillers = repeat(fillvalue)
iters = [chain(it, sentinel(), fillers) for it in args]
try:
for tup in izip(*iters):
yield tup
except IndexError:
pass