split_top_level

zixy.utils.split_top_level(s: str, sep: str = ',', keep_empty: bool = False) list[str][source]

Split s on unnested occurrences of sep.

Commas inside matched pairs of (), [] or {} are ignored. Surrounding whitespace is stripped from the returned items.

Parameters:
  • s – String to split.

  • sep – Single-character separator.

  • keep_empty – Whether to keep empty items. If False, empty items are dropped.

Returns:

Top-level items extracted from s.

Raises:

ValueError – If the input contains unmatched opening or closing delimiters.