Hi, I'd like a generator that takes a sequence and yields tuples containing n items of the sqeuence, but ignoring the 'odd' items. For example
take_group(range(9), 3) -> (0,1,2) (3,4,5) (6,7,8)
This is what I came up with..
def take_group(gen, count):
i=iter(gen)
while True:
yield tuple([i.next() for _ in xrange(count)])
Is this the most efficient solution?
Regards,
Will McGugan
--
http://www.willmcgugan.com
--
http://mail.python.org/mailman/listinfo/python-list
