-2
I have a scenario, a little confused to explain... but I’ll try...
I need to compare listA
with listaB
, where case 1 or more items from listaA
are within the listaB
, I print it on the screen, but in case listaB
have any items that are not on listaA
, nothing happens.
The lists are similar to the ones below:
dns_svc = ['DNS', 's-udp-53', 's-tcp-53', 'junos-dns-udp', 'junos-dns-tcp']
app1 = ['s-tcp-443', 'Domain-logon']
app2 = ['s-tcp-443', 'DNS']
app3 = ['s-udp-53', 's-tcp-80']
app4 = ['DNS']
app5 = ['s-tdp-53', 's-udp-53']
app6 = ['junos-dns-udp', 'junos-dns-tcp']
dns_svc
would be the listaA
, while the lists appx
are the listaB
.
If anyone can make a suggestion.
I made the script below, but it’s bringing me more lines than it should. It should bring me 3 lines:
app1 = ['tcp-443', 'Domain-logon']
app2 = ['tcp-443', 'DNS']
app3 = ['udp-53', 'tcp-80']
app4 = ['DNS']
app5 = ['tcp-53', 's-udp-53']
app6 = ['junos-dns-udp', 'junos-dns-tcp']
applist = [app1, app2, app3, app4, app5, app6]
dns_svc = ['DNS', 's-udp-53', 's-tcp-53', 'junos-dns-udp', 'junos-dns-tcp']
for i in dns_svc:
for a in applist:
if i in a:
print(i)
These items in the lists, they can be repeated within each list or are unique items within each list?
– Augusto Vasques