API#

class listfmt.OrderedListStyle(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#
classmethod from_char(char: str) OrderedListStyle#
Parameters:

char

  • 'A' returns UPPERCASE_ASCII,

  • 'a' returns LOWERCASE_ASCII,

  • 'I' returns UPPERCASE_ROMAN,

  • 'i' returns LOWERCASE_ROMAN,

  • '1' returns NUMBER.

class listfmt.UnorderedListStyle(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)#
for ... in listfmt.iter_ordered_list(items: Collection[str], /, *, reverse: bool = False, step: int = 1, start: int | None = None, style: OrderedListStyle | Literal['a'] | Literal['A'] | Literal['i'] | Literal['I'] | Literal['1'] = OrderedListStyle.NUMBER, recursive: bool = False, _level: int = 0) Generator[tuple[str, str, int], None, None]#
Parameters:
  • items – A sized iterable of strings.

  • reverse – Starts counting from behind.

  • step – Amount of steps when increasing.

  • start – Integer indicating from where to start counting. Defaults to 1.

  • style – Either an item of OrderedListStyle or 'a' for lowercase letters, 'A' for uppercase letters, 'i' for lowercase roman numerals, 'I' for uppercase roman numerals or '1' for integers.

  • recursive – Turns nested iterables into ordered lists too.

Yields:

Each item as a tuple containing the prefix, the content and the level.

for ... in listfmt.iter_unordered_list(items: Iterable[str], /, *, style: str = '*', recursive: bool = False, _level: int = 0) Generator[tuple[str, str, int], None, None]#
Parameters:
  • items – A sized iterable of strings.

  • style – A character to prefix the list items with.

  • recursive – Turns nested iterables into unordered lists too.

Yields:

Each item as a tuple containing the prefix, the content and the level.

listfmt.join_with(items: Collection[str], /, join: str = ', ', *, join_first: str | None = None, join_last: str | None = None) str#

str.join but with more control.

Parameters:
  • items – A sized iterable of strings.

  • join – String that is inserted between all elements in the list.

  • join_first – String that is inserted between the first and second element in the list.

  • join_last

    String that is inserted beteeen the last its predecessor element in the list.

    This has precedence over join_first if there are exactly two elements.

listfmt.ordered_list(*args: Any, join: str = '. ', **kwargs: Any) str#
Parameters:
  • items – A sized iterable of strings.

  • join – String that joins between the prefix and the item.

  • reverse – Starts counting from behind.

  • step – Amount of steps when increasing.

  • start – Integer indicating from where to start counting. Defaults to 1.

  • style – Either an item of OrderedListStyle or 'a' for lowercase letters, 'A' for uppercase letters, 'i' for lowercase roman numerals, 'I' for uppercase roman numerals or '1' for integers.

  • recursive – Turns nested iterables into ordered lists too.

listfmt.reprjoin(string: str, items: Iterable[Any], /) str#

Shorthand for str.join(map(repr, iterable)).

Parameters:
  • string – String that joins each item.

  • items – Items to join the string with.

listfmt.strjoin(string: str, items: Iterable[Any], /) str#

Shorthand for str.join(map(str, iterable)).

Parameters:
  • string – String that joins each item.

  • items – Items to join the string with.

listfmt.unordered_list(*args: Any, join: str = ' ', indent: int = 2, **kwargs: Any) str#
Parameters:
  • items – A sized iterable of strings.

  • join – String that joins between the prefix and the item.

  • style – A character to prefix the list items with.

  • recursive – Turns nested iterables into unordered lists too.