The ToString class
Class for converting list[int]
to strings with specified alphabet.
An instance of this class is callable and used to convert from list[int]
to
str
. The integers in the list are converted to characters according to
their position in the alphabet used to construct a ToString
instance if
one is provided, or using words.human_readable_letter
otherwise.
>>> from libsemigroups_pybind11 import ToString
>>> to_string = ToString("bac")
>>> to_string([0, 1, 2])
'bac'
>>> to_string([0, 1, 0, 1, 0, 0, 0, 2, 0, 2])
'bababbbcbc'
>>> to_string.init() # clear the alphabet
<ToString object with alphabet "">
>>> to_string([0, 1, 2])
'abc'
Contents
Class for converting |
|
Return the alphabet used for conversion. |
|
Check if the current ToString instance can convert a specified letter. |
|
Copy a |
|
Check if the alphabet is defined. |
|
Overloaded function. |
Full API
- class ToString
- __init__(*args, **kwargs)
Overloaded function.
- __call__(self: ToString, input: list[int]) str
Convert a
list[int]
to astr
.This function converts its argument input into a
str
. The characters of input are converted using the alphabet used to construct the object or set viainit()
, or withwords.human_readable_letter
ifempty()
returnsTrue
.- Parameters:
- Returns:
The converted string.
- Return type:
- Raises:
LibsemigroupsError – if the alphabet used to define an instance of
ToString
is not empty and input contains letters that do not correspond to letters of the alphabet.
- alphabet(self: ToString) str
Return the alphabet used for conversion.
This function returns a
str
corresponding to the ordered-set alphabet \(\{a_0, a_1, \dots, a_{n-1}\}\) that the initialisedToString
object will use to convert fromlist[int]
tostr
. Specifically, \(i \mapsto a_i\) where \(i\) will be anint
in a list and \(a_i\) will be a character in astr
.If this function returns the empty string, then conversion will be performed using
words.human_readable_letter
.- Returns:
The alphabet.
- Return type:
- can_convert_letter(self: ToString, l: int) bool
Check if the current ToString instance can convert a specified letter.
This function returns
True
if l can be converted to astr
using this ToString instance, andFalse
otherwise.
- empty(self: ToString) bool
Check if the alphabet is defined.
This function return
True
if no alphabet has been defined, andFalse
otherwise.- Returns:
A whether the alphabet is empty.
- Return type:
- init(*args, **kwargs)
Overloaded function.
- init(self: ToString) ToString
Initialize an existing ToString object.
This function puts a
ToString
object back into the same state as if it had been newly default constructed.- Returns:
self.
- Return type:
See also
- init(self: ToString, alphabet: str) ToString
Initialize an existing Tostring object.
This function puts a
ToString
object back into the same state as if it had been newly constructed from alphabet.- Parameters:
alphabet (str) – the alphabet.
- Returns:
self.
- Return type:
- Raises:
LibsemigroupsError – if there are repeated letters in alphabet.
See also