code: def ngrams(sequence, n, **kwargs):
      """
      Return the ngrams generated from a sequence of items, as an iterator.
      For example:
  
          >>> from nltk.util import ngrams
          >>> list(ngrams([1,2,3,4,5], 3))
          [(1, 2, 3), (2, 3, 4), (3, 4, 5)]
  
      Wrap with list for a list version of this function.  Set pad_left
      or pad_right to true in order to get additional ngrams:
  
          >>> list(ngrams([1,2,3,4,5], 2, pad_right=True))
          [(1, 2), (2, 3), (3, 4), (4, 5), (5, None)]
          >>> list(ngrams([1,2,3,4,5], 2, pad_right=True, right_pad_symbol='</s>'))
          [(1, 2), (2, 3), (3, 4), (4, 5), (5, '</s>')]
          >>> list(ngrams([1,2,3,4,5], 2, pad_left=True, left_pad_symbol='<s>'))
          [('<s>', 1), (1, 2), (2, 3), (3, 4), (4, 5)]
          >>> list(ngrams([1,2,3,4,5], 2, pad_left=True, pad_right=True, left_pad_symbol='<s>', right_pad_symbol='</s>'))
          [('<s>', 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, '</s>')]
  
  
      :param sequence: the source data to be converted into ngrams
      :type sequence: sequence or iter
      :param n: the degree of the ngrams
      :type n: int
      :param pad_left: whether the ngrams should be left-padded
      :type pad_left: bool
      :param pad_right: whether the ngrams should be right-padded
      :type pad_right: bool
      :param left_pad_symbol: the symbol to use for left padding (default is None)
      :type left_pad_symbol: any
      :param right_pad_symbol: the symbol to use for right padding (default is None)
      :type right_pad_symbol: any
      :rtype: sequence or iter
      """
      sequence = pad_sequence(sequence, n, **kwargs)
  
      # sliding_window('ABCDEFG', 4) --> ABCD BCDE CDEF DEFG
      # https://docs.python.org/3/library/itertools.html?highlight=sliding_window#itertools-recipes
      it = iter(sequence)
      window = deque(islice(it, n), maxlen=n)
      if len(window) == n:
          yield tuple(window)
      for x in it:
          window.append(x)
          yield tuple(window)
  
imports: import inspect
  import locale
  import os
  import pydoc
  import re
  import textwrap
  import unicodedata
  import warnings
  from collections import defaultdict, deque
  from itertools import chain, combinations, islice, tee
  from pprint import pprint
  from urllib.request import HTTPPasswordMgrWithDefaultRealm, ProxyBasicAuthHandler, ProxyDigestAuthHandler, ProxyHandler, build_opener, getproxies, install_opener
  from nltk.collections import *
  from nltk.internals import deprecated, raise_unorderable_types, slice_bounds
label_desc: Use image node_id 28 for calling a global function with example usage: ngrams(sequence, n) without return types