code: def ngrams(sequence, n):
      """
      Produce all Nth order N-grams from the sequence.
  
      This will generally be used in an N-gram counting pipeline.
  
      Arguments
      ---------
      sequence : iterator
          The sequence from which to produce N-grams.
      n : int
          The order of N-grams to produce
  
      Yields
      ------
      tuple
          Yields each ngram as a tuple.
  
      Example
      -------
      >>> for ngram in ngrams("Brain", 3):
      ...     print(ngram)
      ('B', 'r', 'a')
      ('r', 'a', 'i')
      ('a', 'i', 'n')
  
      """
      if n <= 0:
          raise ValueError("N must be >=1")
      # Handle the unigram case specially:
      if n == 1:
          for token in sequence:
              yield (token,)
          return
      iterator = iter(sequence)
      history = []
      for hist_length, token in enumerate(iterator, start=1):
          history.append(token)
          if hist_length == n - 1:
              break
      else:  # For-else is obscure but fits here perfectly
          return
      for token in iterator:
          yield tuple(history) + (token,)
          history.append(token)
          del history[0]
      return
  
imports: import itertools
label_desc: Use image node_id 2 for calling a global function with example usage: ngrams(sequence, n) without return types