Before this wode was written that iterates over a file (ipaddress) using nested loops and a module (ipaddress). Now i would like to optimize using list comprehension.
import ipaddress
tmp1=open('Path\\Test-ip.txt', 'r+')
tmp2=open('Path\\-ip.txt', 'w+')
tmp1=tmp1.readlines()
for i in tmp1:
i="".join(i.split())
i=ipaddress.ip_network(i,False)
for j in tmp1:
j="".join(j.split())
j=ipaddress.ip_network(j,False)
if j != i:
if ipaddress.IPv4Network(j).supernet_of(i):
tmp2.write(str(i))
tmp2.write('\n')
#Using List Comprehension
tmp1=open('Path\\Test-ip.txt', 'r+')
tmp2=open('Path\\Result-ip.txt', 'w+')
tmp1=tmp1.readlines()
tmp3=[ (("").join(i.split())) (("").join(j.split())) (ipaddress.ip_network(i)) (ipaddress.ip_network(j)) (tmp2.(write(str(i)))) for i in tmp1 for j in tmp1 if i!=j if ipaddress.IPv4Network(j).supernet_of(i)]