Reading 3 objects at a time from list
Vito De Tullio
zak.mc.kraken at libero.it
Sat Apr 11 21:48:09 CEST 2009
> it works and I like slices, but I was wondering if there was another
> way of doing the same thing, maybe reading the numbers in groups of
> arbitrary length n...
def grouper(n, iterable, fillvalue=None):
"grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx"
args = [iter(iterable)] * n
return izip_longest(fillvalue=fillvalue, *args)
and it's *damned* fast!
More information about the Python-list