python - 有效地删除具有特定值的集合中的元组
问题描述
我有一组元组,例如 set_of_tuples = {(1,2}, (1,3), (1,), (4,3)} 我想删除所有包含例如 a 的元组,1
我想知道有多少。如何有效地做到这一点?
我的做法:
set_of_tuples={(1,2),(1,3),(1,),(4,3)}
to_be_removed = set()
i=0
for val in set_of_tuples:
if 1 in val:
i=i+1
to_be_removed.add(val)
set_of_tuples = set_of_tuples-to_be_removed
解决方案
我的代码在这个链接中,请看这个!!!:)
推荐阅读
- azure - 如何在 golang 中生成 x5t 标头值
- flutter - 颤振自动填充不适用于文本字段
- amazon-dynamodb - GSI 全局二级索引是否允许使用 AWS DynamoDB 稀疏索引?
- python-3.x - ValueError:不支持的“设备类型”
- python - 无法理解 Python 用户定义的函数
- spring - Spring Kafka 死消息队列和重试
- javascript - 隐藏和取消隐藏列 - Google 表格
- python - 无法在 beagle bone 上安装 opencv-python
- django - sweetalert 不适用于 django 模板
- python - 将函数应用到 arr 并打印出来