相关疑难解决方法(0)

从Python中删除字符串标点符号的最佳方法

似乎应该有一个比以下更简单的方法:

import string
s = "string. With. Punctuation?" # Sample string 
out = s.translate(string.maketrans("",""), string.punctuation)
Run Code Online (Sandbox Code Playgroud)

在那儿?

python string punctuation

578
推荐指数
20
解决办法
65万
查看次数

从Unicode格式的字符串中删除标点符号

我有一个函数,从字符串列表中删除标点符号:

def strip_punctuation(input):
    x = 0
    for word in input:
        input[x] = re.sub(r'[^A-Za-z0-9 ]', "", input[x])
        x += 1
    return input
Run Code Online (Sandbox Code Playgroud)

我最近修改了我的脚本以使用Unicode字符串,所以我可以处理其他非西方字符.当遇到这些特殊字符并且只返回空的Unicode字符串时,此函数会中断.如何从Unicode格式的字符串中可靠地删除标点符号?

python unicode

40
推荐指数
4
解决办法
2万
查看次数

从Python列表项中删除标点符号

我有一个清单

['hello', '...', 'h3.a', 'ds4,']
Run Code Online (Sandbox Code Playgroud)

这应该变成了

['hello', 'h3a', 'ds4']
Run Code Online (Sandbox Code Playgroud)

我想只删除字母和数字完整的标点符号.标点符号是string.punctuation常量中的任何内容.我知道这很简单,但我在python中有点noobie所以......

谢谢,giodamelio

python list

7
推荐指数
2
解决办法
5万
查看次数

标签 统计

python ×3

list ×1

punctuation ×1

string ×1

unicode ×1