iterate_sequence_boustrophedon

sequencetools.iterate_sequence_boustrophedon(iterable, duplicates=False)

Iterates iterable boustrophedon.

Iterates iterable first forward and then backward. Duplicates neither first nor last elements:

>>> iterable = [1, 2, 3, 4, 5]
>>> generator = sequencetools.iterate_sequence_boustrophedon(
...     iterable, duplicates=False)
>>> list(generator)
[1, 2, 3, 4, 5, 4, 3, 2]

Iterates iterable first forward and then backward. Duplicates both first and last elements:

>>> iterable = [1, 2, 3, 4, 5]
>>> generator = sequencetools.iterate_sequence_boustrophedon(
...     iterable, duplicates=True)
>>> list(generator)
[1, 2, 3, 4, 5, 5, 4, 3, 2, 1]

Returns generator.