code: def check_bidi(chars):
      
  
      # the empty string is valid, as it cannot violate the RandALCat constraints
      if not chars:
          return
  
      # first_is_RorAL = unicodedata.bidirectional(chars[0]) in {"R", "AL"}
      # if first_is_RorAL:
  
      has_RandALCat = any(is_RandALCat(c) for c in chars)
      if not has_RandALCat:
          return
  
      has_LCat = any(is_LCat(c) for c in chars)
      if has_LCat:
          raise ValueError("L and R/AL characters must not occur in the same"
                           " string")
  
      if not is_RandALCat(chars[0]) or not is_RandALCat(chars[-1]):
          raise ValueError("R/AL string must start and end with R/AL character.")
docs: Check proper bidirectionality as per stringprep. Operates on a list of
      unicode characters provided in `chars`.