iterating "by twos"
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Tue Jul 29 14:04:13 EDT 2008
Something like this may be fast enough:
>>> from itertools import izip
>>> xpartition = lambda seq, n=2: izip(*(iter(seq),) * n)
>>> xprimes = (x for x in xrange(2, 100) if all(x % i for i in xrange(2, x)))
>>> list(xpartition(xprimes))
[(2, 3), (5, 7), (11, 13), (17, 19), (23, 29), (31, 37), (41, 43),
(47, 53), (59, 61), (67, 71), (73, 79), (83, 89)]
Bye,
bearophile
More information about the Python-list
mailing list