[Python] 纯文本查看 复制代码
data = [('rule 37 name S07100275', ''), ('', 'service telnet'), ('', 'service tcp_20060'), ('rule 38 name S7100275-2', ''), ('', 'telnet'), ('', 'service tcp_20060'), ('rule 36 name cy_test', ''), ('', 'service http'), ('', 'service https')]
result = []
current_rule = None
for item in data:
if item[0].startswith('rule'):
current_rule = item[0]
elif item[1].startswith('service telnet'):
result.append((current_rule, item[1]))
for rule, service in result:
print(f'{rule}\n {service}')
cv搞定 |