brainpy.tools.codes.word_replace
brainpy.tools.codes.word_replace#
- brainpy.tools.codes.word_replace(expr, substitutions, exclude_dot=True)[source]#
Applies a dict of word substitutions.
The dict
substitutions
consists of pairs(word, rep)
where each wordword
appearing inexpr
is replaced byrep
. Here a ‘word’ means anything matching the regexp\bword\b
.Examples
>>> expr = 'a*_b+c5+8+f(A)' >>> print(word_replace(expr, {'a':'banana', 'f':'func'})) banana*_b+c5+8+func(A)