code: def _iter_wave(iterable, count=0):
          
          up = True
          pos = 0
          i = 0
          try:
              end = len(iterable)
          except TypeError:
              iterable = list(iterable)
              end = len(iterable)
  
          # Stop on count, or run forever.
          while (i < count) if count > 0 else True:
              try:
                  stop = yield iterable[pos]
                  # End of generator (user sent the stop signal)
                  if stop:
                      break
              except IndexError:
                  # End of iterable, when len(iterable) is < count.
                  up = False
  
              # Change directions if needed, otherwise increment/decrement.
              if up:
                  pos += 1
                  if pos == end:
                      up = False
                      pos = end - 2
              else:
                  pos -= 1
                  if pos < 0:
                      up = True
                      pos = 1
              i += 1
docs: Move from beginning to end, and then end to beginning, a number of
              iterations through an iterable (must accept len(iterable)).
              Example:
                  print(' -> '.join(_iter_wave('ABCD', count=8)))
                  >> A -> B -> C -> D -> C -> B -> A -> B
  
              If `count` is less than 1, this will run forever.
              You can stop it by sending a Truthy value into the generator:
                  gen = self._iter_wave('test')
                  for c in gen:
                      if c == 's':
                          # Stop the generator early.
                          gen.send(True)
                      print(c)