code: def is_valid_by_reber(word):
      """
      Сhecks whether a word belongs to grammar Reber.
  
      Parameters
      ----------
      word : str or list of letters
          The word that you want to test.
  
      Returns
      -------
      bool
          ``True`` if word valid by Reber grammar and
          ``False`` otherwise.
  
      Examples
      --------
      >>> from neupy.datasets import is_valid_by_reber
      >>>
      >>> is_valid_by_reber('TTS')
      True
      >>> is_valid_by_reber('STS')
      False
      >>>
      >>> is_valid_by_reber(['T', 'T', 'S'])
      True
      >>> is_valid_by_reber(['S', 'T', 'S'])
      False
      """
      if not word.endswith("S"):
          return False
  
      position = 0
      for letter in word:
          possible_letters = reber_rules[position]
          letters = [step[0] for step in possible_letters]
          if letter not in letters:
              return False
          _, position = possible_letters[letters.index(letter)]
      return True
  
imports: import math
  from random import choice, randint
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: is_valid_by_reber(word) and returns: True, False, False