Loop over list of pairs

Alexander Schmolck a.schmolck at gmx.net
Fri Jun 6 15:05:27 EDT 2003


Alexander Schmolck <a.schmolck at gmx.net> writes:

> def xgroup(it, n=2):
>     assert n>1    # ensure it doesn't loop forever
>     it = iter(it)
>     perTuple = xrange(n)
>     while 1:
>         yield tuple([it.next() for i in perTuple])
> 
> 'as

of course it should be ``assert n>0``

'as




More information about the Python-list mailing list