string_utils

Functions

list_to_human(iterable[, conjunction, oxford_comma])

Convert an iterable to a human-readable string.

split_camel_case(string)

Split a CamelCase string into its constituent words.

Module Contents

string_utils.list_to_human(iterable, conjunction='and', oxford_comma=False)

Convert an iterable to a human-readable string.

Parameters:
  • iterable (list or tuple) – The list of strings to convert to a single natural language string.

  • conjunction (str, optional) – The conjunction with which to join the last two elements of the list, for example “and” (default).

  • oxford_comma (bool, optional) – If True, an “Oxford comma” will be added before the conjunction when there are three or more elements in the list. Default is False.

Return type:

str

Example

>>> list_to_human(["sausage", "egg", "chips"])
'sausage, egg and chips'
string_utils.split_camel_case(string)

Split a CamelCase string into its constituent words.

Parameters:

string (str) – The string to split by camel case words.

Return type:

list

Example

>>> split_camel_case("ACamelCaseString")
['A', 'Camel', 'Case', 'String']