【发布时间】:2021-03-16 03:55:39
【问题描述】:
以下代码运行良好,但任何人都可以指导如何简化它。
newrelicid 是一个字典,其中包含“数字”作为键和“某些字符串”作为值(字符串可以包含子字符串,如 prod、test、local 等
)
基本上我试图忽略包含来自列表['dev','staging','qat','uat','local','eu']的子字符串的值( j )@
样本newrelicid值
{1: 'Service PROD', 2: 'service', 3: 'guess-service (Production)', 4: 'check-service (Dev)', 5: 'analytics-service (Staging)' }
循环:
for i,j in newrelicid.items():
if 'staging' not in j.lower() and not 'qat' in j.lower() and not 'uat' in j.lower() and not 'local' in j.lower() and not 'eu' in j.lower() and not 'dev' in j.lower():
print(j)
【问题讨论】:
标签: python dictionary