[Python-ideas] zip_strict() or similar in itertools ?

Wolfgang Maier wolfgang.maier at biologie.uni-freiburg.de
Thu Apr 4 15:07:28 CEST 2013


Alfredo Solano Martínez <asolano at ...> writes:

> # None of your data will be this
> class Marker(): pass
> 
> # Same as the docs recipes
> def grouper(n, iterable, fillvalue=None):
>     args = [iter(iterable)] * n
>     return itertools.zip_longest(*args, fillvalue=fillvalue)
> 
> # And then do something like
> for t in grouper(3, 'ABCDEFG', Marker):
>     if Marker in t: print('Marker) # or raise ValueError, ...
> 
> Alfredo
> 

Thanks for sharing this! It's the same basic idea as in Peter's
strict_grouper solution, which integrates the whole thing in one function.

Wolfgang




More information about the Python-ideas mailing list