switch recipe?
Terry Reedy
tjreedy at udel.edu
Sat Jul 13 12:10:55 EDT 2002
"Mark McEahern" <marklists at mceahern.com> wrote in message > Perhaps
what I'm still looking for is a way to
> weave-two-iterators-with-a-function all at once. One solution would
be to
> modify or wrap repeating_alternator() so that it was finite--then I
could
> just use map.
*IF* you know the 'length' of iterator, or the iterable it is based
on, as in the examples used in preious articles in this thread, this
is easy and clean:
def firstn(it, n):
while n:
yield it.next()
n -= 1
n = len(iterator) # or whatever
map(color_item, iterator, firstn(alternator, n))
Terry J. Reedy
More information about the Python-list
mailing list