我有这个示例字符串:happy t00 go 129.129我想只保留空格和字母.到目前为止我能够提出的非常有效的是:
print(re.sub("\d", "", 'happy t00 go 129.129'.replace('.', '')))
Run Code Online (Sandbox Code Playgroud)
但它只针对我的示例字符串.如何删除除字母和空格以外的所有字符?
我试图在循环的每次迭代中将变量(lett)更改为字母表中的下一个字母.我还必须能够在脚本开头将此变量设置为某个字母(并且首字母将根据脚本的使用而变化).我开始创建以下代码:
初始脚本(当我还在学习时):
while lett_trig == 2:
if set_lett == 2:
lett = "a"
if set_lett == 3:
lett = "b"
if set_lett == 4:
lett = "c"
if set_lett == 5:
lett = "d"
if set_lett == 6:
lett = "e"
if set_lett == 7:
lett = "f"
if set_lett == 8:
lett = "g"
if set_lett == 9:
lett = "h"
#... and this goes on till it reaches if set_let == 27: lett = "z"
set_lett += 1 …Run Code Online (Sandbox Code Playgroud)