multiplied.core.utils package#
Submodules#
multiplied.core.utils.bool module#
- multiplied.core.utils.bool.isalpha(ch: str) bool[source]#
Return True if string is exactly one alphabetic character
- multiplied.core.utils.bool.ischar(ch: str) bool[source]#
Return True if string is exactly one character
multiplied.core.utils.char module#
- multiplied.core.utils.char.allchars(
- matrix: list[list[str]],
- *,
- hash: list[int | bool] = [],
Returns set of unique characters from a nested list.
- Parameters:
matrix (list[list[str]]) – Matrix of characters to extract unique characters from.
hash (list[int | bool], optional) – List of bools or 0s and 1s indicating if a row contains characters.
- Return type:
set[str]
Notes
Ignores underscore characters and converts characters to uppercase
See also
MatrixMultiplied 2D Matrix Object
Examples
>>> allchars([['A', 'B'], ['C', 'D']]) {'A', 'B', 'C', 'D'}
- multiplied.core.utils.char.chargen() Generator[str][source]#
Return Generator characters from A to Z.
- Yields:
str
Example
>>> x = chargen()
>>> next(x) 'A' >>> next(x) 'B' >>> next(x) 'C'
- multiplied.core.utils.char.chartff(ch: str) Generator[str][source]#
Generator to flip flop between upper and lowercase characters.
- Parameters:
ch (str) – Single alphabetic character to flip flop.
- Yields:
str – Upper or lowercase version of the input character.
- Raises:
ValueError – If input is not a single alphabetic character.
Examples
>>> x = chartff('a') >>> next(x) 'a' >>> next(x) 'A' >>> next(x) 'a'
- multiplied.core.utils.char.to_int_matrix(matrix: list[list[str]]) list[int][source]#
Converts a matrix of characters to a matrix of integers
- Parameters:
matrix (list[list[str]]) – Matrix of characters to convert from 2D Multiplied formatted matrix into to list of integers.
- Return type:
list[int]
Examples
>>> to_int_matrix([['_', '1', '_'], ['1', '0', '1']]) [2, 5]
multiplied.core.utils.pretty module#
- multiplied.core.utils.pretty.pretty( ) str[source]#
Format Multiplied types, or list as a string.
- Parameters:
listy_object (Any) – List or Dict style object to format as a string.
- Return type:
str
Examples
>>> pretty(mp.Matrix(4)) ____0000 ___0000_ __0000__ _0000___
- multiplied.core.utils.pretty.pretty_dict(listy_dict: Any) str[source]#
Format Dict type object as a string:
>>> {0: [[1, _, _],[_, 2, _],[_, _, 3]], >>> 1: [[a, _, _],[_, b, _],[_, _, c]], >>> 2: [[x, y, z],[x, y, z],[x, y, z]]} 0:{ 1__ _2_ __3 } ...
- multiplied.core.utils.pretty.pretty_nested_list(
- listy_object: Any,
- *,
- whitespace=False,
Format nested list as a string.
- Parameters:
listy_object (Any) – The nested list to be formatted.
whitespace (bool, optional) – Whether to add whitespace between elements, by default False.
Examples
>>> pretty_nested_list([[1, _, _],[_, 2, _],[_, _, 3]]) 1__ _2_ __3