小编Gro*_*onk的帖子

从Python3.3中的字符串中删除字母和空格以外的所有内容

我有这个示例字符串:happy t00 go 129.129我想只保留空格和字母.到目前为止我能够提出的非常有效的是:

print(re.sub("\d", "", 'happy t00 go 129.129'.replace('.', '')))
Run Code Online (Sandbox Code Playgroud)

但它只针对我的示例字符串.如何删除除字母和空格以外的所有字符?

python regex translate python-3.3

8
推荐指数
3
解决办法
1万
查看次数

如何在Python中为循环中的变量创建字母进展?

我试图在循环的每次迭代中将变量(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)

python

1
推荐指数
1
解决办法
427
查看次数

标签 统计

python ×2

python-3.3 ×1

regex ×1

translate ×1