I have a list like
['hello', '...', 'h3.a', 'ds4,']
this should turn into
['hello', 'h3a', 'ds4']
and i want to remove only the punctuation leaving the letters and numbers intact.
Punctuation is anything in the string.punctuation constant.
I know that this is gunna be simple but im kinda noobie at python so...
Thanks,
giodamelio
解决方案
Assuming that your initial list is stored in a variable x, you can use this:
>>> x = [''.join(c for c in s if c not in string.punctuation) for s in x]
>>> print(x)
['hello', '', 'h3a', 'ds4']
To remove the empty strings:
>>> x = [s for s in x if s]
>>> print(x)
['hello', 'h3a', 'ds4']
python去除列表中的逗号 python怎么删除列表中的逗号
转载文章标签 python去掉列表的逗号 python 解决方案 文章分类 Python 后端开发
-
带你了解Python中的”容器“:列表、元组、集合、字典
Python中的容器可以解释为:一个包含多个数据项的实体。容器数据类型也称为复合数据类型。
python 列表 元组 集合 字典 -
python_列表的方法
python_列表的方法
指定位置 删除元素 升序 -
python列表去除逗号 python去掉列表的括号和逗号python列表去除逗号
-
Python列表中逗号与元素间有空格 python 列表 逗号
实现python中的List以存储各种类型数据的序列。但是,python包含六种能够存储序列的数据类型,但最常见和可靠的类型是列表。列表可以定义为值集合或不同类型的项目。列表中的项目用逗号(,)分隔,并用方括号[]括起来。列表可以定义如下:L1 = ["John", 102, "USA"]L2 = [1, 2, 3,&
Python列表中逗号与元素间有空格 python支持的数据类型list List IT Python -
hive 同一个表中算比例
本文目录:数据准备日活计算 SQL计算日活 pandas计算日活留存率计算 SQL计算 次日留存计算 多日留存计算 pandas方式小
hive 同一个表中算比例 SQL 数据 MySQL