les_iterables.parsing module

Summary

Functions:

expand_numbered_list

Expands a string containing numbered items into a list of integers.

range_from_text

A range of integers from a textual description.

Reference

les_iterables.parsing.range_from_text(text_range: str, separator='-') range[source]

A range of integers from a textual description.

Parameters:

text_range – A string containing an integer or a string of the form “<first>-<last>” such as “7-10” describing the inclusive ends of a range of integers. Descending ranges such as “10-7”, open ranges such as “10-“are not supported.

Returns:

A range object.

Raises:
  • ValueError – If the string could not be parsed as an non-descending range of at least one

  • item.

les_iterables.parsing.expand_numbered_list(text, *, separator=',', range_separator='-')[source]

Expands a string containing numbered items into a list of integers.

e.g. “1, 2, 5, 7-10, 15, 20-25” -> [1, 2, 5, 7, 8, 9, 10, 15, 20, 21, 22, 23, 24, 25]

Descending ranges such as “10-7”, open ranges such as “10-“are not supported.

Parameters:
  • text – A string containing separated integers and non-descending integer ranges.

  • separator – The item separator. Defaults to “,”.

  • range_separator – The separator between the beginning and end of a range. Defaults to “-”

Yields:

An iterable series of integers.

Raises:

ValueError – If the list could not be parsed.