python - Python基于.count从列表中删除列表

标签 python list count

我的列表中有以下列表

results=[['hgd', '2.96', '4,433,389', '-13.7'], ['bbd.a', '2.25', '1,209,421', '-13.1'], ['mri.u', '8.60', '3,000', '-8.5'], ['iam', '1.06', '1,000', '-7.8'], ['hnd', '21.76', '1,180,466', '-7.6'], ['tth', '0.97', '41,777', '-7.6'], ['bbd.b', '1.89', '32,423,597', '-7.4'], ['bbd.pr.c', '15.20', '43,737', '-7.3'], ['esp', '1.96', '87,604', '-7.1'], ['enl', '34.00', '5,239', '-6.2'], ['rmp', '1.83', '2,688,261', '-5.7'], ['amm', '1.39', '63,301', '-5.4'], ['vrx', '41.83', '1,664,689', '-5.4'], ['xtc', '13.45', '63,453', '-5.3'], ['cxr', '36.48', '1,642,197', '-5.0']]

此列表每天更新。有时会有一个列表,其中第一个元素有两个句点 (.),如下所示 bbd.pr.c

['bbd.pr.c', '15.20', '43,737', '-7.3']

发生这种情况时,我希望删除整个列表。不确定如何去做这件事。使用计数功能。

.count('.')<=1

有什么帮助吗?

最佳答案

对于 python 2,请使用 filter :

results=[['hgd', '2.96', '4,433,389', '-13.7'], ['bbd.a', '2.25', '1,209,421', '-13.1'], ['mri.u', '8.60', '3,000', '-8.5'], ['iam', '1.06', '1,000', '-7.8'], ['hnd', '21.76', '1,180,466', '-7.6'], ['tth', '0.97', '41,777', '-7.6'], ['bbd.b', '1.89', '32,423,597', '-7.4'], ['bbd.pr.c', '15.20', '43,737', '-7.3'], ['esp', '1.96', '87,604', '-7.1'], ['enl', '34.00', '5,239', '-6.2'], ['rmp', '1.83', '2,688,261', '-5.7'], ['amm', '1.39', '63,301', '-5.4'], ['vrx', '41.83', '1,664,689', '-5.4'], ['xtc', '13.45', '63,453', '-5.3'], ['cxr', '36.48', '1,642,197', '-5.0']]

results = filter(lambda l: l[0].count('.') <= 1, results)

对于Python 3:

results = list(filter(lambda l: l[0].count('.') <= 1, results))

关于python - Python基于.count从列表中删除列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36971981/

相关文章:

list - Haskell:有没有一种惯用的方式将列表中的每个项目插入到它自己的列表中?

postgresql - 如何在不锁定整个表的情况下强制 Postgres 返回合理的行数?

sql - PostgreSQL 检查匹配正则表达式的表数

SQL count 连接不同的多列

日期时间相关值的 Python Numpy 或 Pandas 线性插值

python - 在 python 3.4.3 上安装 pyinstaller

java - 将参数从 Java 传递到 Python,反之亦然

python - 严格递增子序列的最小数量

python - Python 中省略号的混淆

python - 在元组列表中搜索最小值