python - 将列表与元组列表进行比较
问题描述
我有一个元组列表,例如
journeylist = [("uk_Frank_3734823","342-2432-242-2342",2,3434-3434),("uk_joe_3734823","342-2432-242-2342",2,3434-3434)]
和一个列表,例如
exclusion = ["joe","jack","alice"]
我想将排除列表与每个元组的 0 索引进行比较。该值在任何情况下都可以是,例如73473_Jack_uk
,列表具有jack
. 他们应该匹配。如果存在匹配,则必须删除整个元组或将非匹配添加到另一个列表中。
解决方案
我会通过降低第一个值的大小写并exclusion
对照它检查列表来做到这一点:
lowered_exclusion = [excl.lower() for excl in exclusion]
filtered_journeylist = []
for journey in journeylist:
first = journey[0].lower()
if not any(excl in first for excl in lowered_exclusion):
filtered_journeylist.append(journey)
推荐阅读
- deployment - 如何在 gitlab-ci 管道中获取合并请求信息?
- sybase - ct_connect():网络数据包层:内部网络库错误:Net-Lib 协议驱动程序调用连接两个端点失败 stackoverflow
- react-native - 仅 iOS 中 react-native-twitter-signin 中的 Twitter 登录错误
- apache-spark - 有没有办法重新分配持久的数据集复制?
- php - 在 AWS Elasticbeanstalk 上部署 PHP 应用程序
- here-api - 给定纬度和经度,如何从这里的地图中检索速度限制?
- javascript - 如何在 NodeJS 中运行无限阻塞进程?
- nestjs - 如何在 NestJS 中跨模块全局注入价值?
- python - 对 excel 数据进行哈希处理以检测使用 openpyxl 更改的数据
- intellij-idea - 打印 IntelliJ IDEA 有效系统属性