假设您的初始列表存储在变量x中,则可以使用以下命令:
>>> x = [''.join(c for c in s if c not in string.punctuation) for s in x]>>> print(x)['hello', '', 'h3a', 'ds4']
删除空字符串:
>>> x = [s for s in x if s]>>> print(x)['hello', 'h3a', 'ds4']

假设您的初始列表存储在变量x中,则可以使用以下命令:
>>> x = [''.join(c for c in s if c not in string.punctuation) for s in x]>>> print(x)['hello', '', 'h3a', 'ds4']
删除空字符串:
>>> x = [s for s in x if s]>>> print(x)['hello', 'h3a', 'ds4']