__init__ constructor

init

Initializes a new CharacterReplacementPair.

def __init__(self, character, replacement):
    ...
Parameter Type Description
character str The character to be replaced.
replacement str The replacement.

Example

from groupdocs.search.dictionaries import CharacterReplacementPair

pairs = [
    CharacterReplacementPair("Ä", "a"),
    CharacterReplacementPair("ä", "a"),
    CharacterReplacementPair(0x1D400, 0x0061),  # Mathematical bold capital A → 'a'
]

init

Initializes a new CharacterReplacementPair.

def __init__(self, character, replacement):
    ...
Parameter Type Description
character int The Unicode code point to be replaced.
replacement int The replacement Unicode code point.

Example

from groupdocs.search.dictionaries import CharacterReplacementPair

# Adding character replacements to a dictionary
pairs = [
    CharacterReplacementPair("Ä", "a"),
    CharacterReplacementPair("ä", "a"),
    CharacterReplacementPair(0x1D400, 0x0061),  # Mathematical bold capital A → 'a'
]
replacements.add_range(pairs)

# Creating replacements for all lowercase characters
character_replacements = []
for code_point in range(0x10000):
    character = chr(code_point)
    repl = character.lower()
    if repl != character and len(repl) == 1:
        character_replacements.append(CharacterReplacementPair(character, repl))

See Also