pairs from a list
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Tue Jan 22 10:25:56 EST 2008
Alan Isaac>What is the fastest way? (Ignore the import time.)<
Maybe someday someone will realize such stuff belongs to the python
STD lib...
If you need a lazy generator without padding, that splits starting
from the start, then this is the faster to me if n is close to 2:
def xpartition(seq, n=2):
return izip( *(iter(seq),)*n )
If you need the faster greedy version without padding then there are
two answers, one for Psyco and one for Python without... :-)
If you need padding or to start from the end then there are more
answers...
Bye,
bearophile
More information about the Python-list
mailing list