code: def _check_and_convert_to_indices(
      opt: Sequence[Any],
      default_values: Union[Sequence[Any], Any, None],
  ) -> Optional[List[int]]:
      """Perform validation checks and return indices based on the default values."""
      if default_values is None and None not in opt:
          return None
  
      if not isinstance(default_values, list):
          # This if is done before others because calling if not x (done
          # right below) when x is of type pd.Series() or np.array() throws a
          # ValueError exception.
          if is_type(default_values, "numpy.ndarray") or is_type(
              default_values, "pandas.core.series.Series"
          ):
              default_values = list(cast(Sequence[Any], default_values))
          elif not default_values or default_values in opt:
              default_values = [default_values]
          else:
              default_values = list(default_values)
  
      for value in default_values:
          if value not in opt:
              raise StreamlitAPIException(
                  "Every Multiselect default value must exist in options"
              )
  
      return [opt.index(value) for value in default_values]
  
imports: from dataclasses import dataclass
  from textwrap import dedent
  from typing import TYPE_CHECKING, Any, Callable, Generic, List, Optional, Sequence, Union, cast, overload
  from streamlit.elements.form import current_form_id
  from streamlit.elements.utils import check_callback_rules, check_session_state_rules, get_label_visibility_proto_value, maybe_coerce_enum_sequence
  from streamlit.errors import StreamlitAPIException
  from streamlit.proto.MultiSelect_pb2 import MultiSelect
  from streamlit.runtime.metrics_util import gather_metrics
  from streamlit.runtime.scriptrunner import ScriptRunContext, get_script_run_ctx
  from streamlit.runtime.state import WidgetArgs, WidgetCallback, WidgetKwargs, register_widget
  from streamlit.runtime.state.common import compute_widget_id
  from streamlit.type_util import Key, LabelVisibility, OptionSequence, T, check_python_comparable, ensure_indexable, is_iterable, is_type, maybe_raise_label_warnings, to_key
label_desc: Use image node_id 3 for calling a global function with example usage: _check_and_convert_to_indices(opt, default_values) and returns: unknown, None