old_contents: """Simple examples calculating iterable permutations.
  
  Example is taken from https://docs.python.org/3.5/library/itertools.html.
  
  To profile this with vprof run:
      vprof -c cmh -s permutations.py
  """
  
  def permutations(iterable, r=None):
      pool = tuple(iterable)
      n = len(pool)
      r = n if r is None else r
      if r > n:
          return
      indices = list(range(n))
      cycles = list(range(n, n-r, -1))
      yield tuple(pool[i] for i in indices[:r])
      while n:
          for i in reversed(range(r)):
              cycles[i] -= 1
              if cycles[i] == 0:
                  indices[i:] = indices[i+1:] + indices[i:i+1]
                  cycles[i] = n - i
              else:
                  j = cycles[i]
                  indices[i], indices[-j] = indices[-j], indices[i]
                  yield tuple(pool[i] for i in indices[:r])
                  break
          else:
              return
  
  print(list(permutations('ABCDEFGED', 2)))
  
new_contents: """Simple examples calculating iterable permutations.
  
  Example is taken from https://docs.python.org/3.5/library/itertools.html.
  
  To profile this with vprof run:
      vprof -c cmh permutations.py
  """
  
  def permutations(iterable, r=None):
      pool = tuple(iterable)
      n = len(pool)
      r = n if r is None else r
      if r > n:
          return
      indices = list(range(n))
      cycles = list(range(n, n-r, -1))
      yield tuple(pool[i] for i in indices[:r])
      while n:
          for i in reversed(range(r)):
              cycles[i] -= 1
              if cycles[i] == 0:
                  indices[i:] = indices[i+1:] + indices[i:i+1]
                  cycles[i] = n - i
              else:
                  j = cycles[i]
                  indices[i], indices[-j] = indices[-j], indices[i]
                  yield tuple(pool[i] for i in indices[:r])
                  break
          else:
              return
  
  print(list(permutations('ABCDEFGED', 2)))
  
subject: Update example.