以下のコードがどのように機能するかを理解するのに苦労しています。これはhttp://docs.python.org/library/itertools.html#itertools.izip_longestからのもので、izip_longest イテレータに相当する純粋な Python です。私は特にセンチネル機能に戸惑っています。どのように機能しますか?
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