擅长:python、mysql、java
<p>python内置了重新映射字符串:使用<a href="https://docs.python.org/3/library/stdtypes.html#str.maketrans" rel="nofollow noreferrer">^{<cd1>}</a>和<a href="https://docs.python.org/3/library/stdtypes.html#str.translate" rel="nofollow noreferrer">^{<cd2>}</a>可以执行以下操作:</p>
<pre><code>intab = "helo" # ...add the full alphabet and other characters
outtab = "⠓⠑⠇⠕" # and the characters you want them translated to
transtab = str.maketrans(intab, outtab)
strg = "hello"
print(strg.translate(transtab)) # ⠓⠑⠇⠇⠕
</code></pre>
<p>请注意,<code>intab</code>的长度必须与{<cd4>}的长度匹配,如果只向<code>maketrans</code>传递2个参数(可以传递第三个参数;请参阅doc)。在</p>