Excuse me again, I just relized that my algorithm was flawed. I just inserted 
in my function the brilliant algorithm of Mark Dickinson and now it works:

import itertools as itools

    def segment(it, n=1):
        if n < 1:
            raise ValueError(f"Number of segment must be > 0, {n} found")
        
        try:
            len_it = len(it)
            it[0:0]
            it_true = it
        except TypeError:
            it_true = tuple(it)
            len_it = len(it_true)
        
        if len_it < n:
            err = f"Iterable length {len_it} must be greater than number of 
segments {n}"
            raise ValueError(err)
        
        return (
            [it_true[i:j] for i, j in zip((0, ) + startends, startends + 
(len_it, ))] 
                for startends in itools.combinations(range(1, len_it), n-1)
        )
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/KYMYVYHLILBWOSQ4LSVBWON723HJKH3D/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to