Peter Otten: > which is almost identical to the last example in > http://docs.python.org/lib/itertools-example.html
I see, thank you. I haven't had enoug time and brain to fix it (and the OP question seemed like homework, so leaving some other things to do is positive). I think still that too much clever code can be bad, it isn't easy to understand, fix and modify if you need something a little different. To solve such problem in 'production code' I probably prefer a longer function like the one I have shown. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list