找到小写(未移位)形式的符号

DCA*_*CA- 5 python string

x = "Foo 890 bar *()"
Run Code Online (Sandbox Code Playgroud)

我怎样才能得到小写字母,包括"*()"被"未移位"回到890?期望的结果:

foo 890 bar 890
Run Code Online (Sandbox Code Playgroud)

不需要的:

x.lower() => "foo 890 bar *()"
Run Code Online (Sandbox Code Playgroud)

Joh*_*ica 6

不移位取决于键盘布局.它不是通用映射.你可以硬编码一个.

unshift = {
    '!': '1', '@': '2', '#': '3', '$': '4', '%': '5',
    '^': '6', '&': '7', '*': '8', '(': '9', ')': '0',
}

x = ''.join(unshift.get(c, c.lower()) for c in x)
Run Code Online (Sandbox Code Playgroud)

编写该地图的另一种更紧凑的方法是:

unshift = dict(zip('!@#$%^&*()', '1234567890'))
Run Code Online (Sandbox Code Playgroud)