code: def form_ngrams(sequence, n):
      history = []
      while n > 1:
          # PEP 479, prevent RuntimeError from being raised when StopIteration bubbles out of generator
          try:
              next_item = next(sequence)
          except StopIteration:
              # no more data, terminate the generator
              return
          history.append(next_item)
          n -= 1
      for item in sequence:
          history.append(item)
          yield tuple(history)
          del history[0]
  
imports: import re
  import string
  import timeit
  import pickle
  import traceback
  from pprint import pprint
label_desc: Use image node_id 1 for calling a global function with example usage: form_ngrams(sequence, n) without return types