mask_dict = {}
for i in test:
mask = IPv4Network('{}/24'.format(i), strict = False)
for j in test:
if IPv4Address(j) in mask:
if mask in mask_dict:
mask_dict[mask].append(j)
else:
mask_dict[mask] = [j]
test.remove(j)
mask_dict = {}
for i in test:
mask = IPv4Network('{}/24'.format(i), strict = False)
if mask in mask_dict:
mask_dict[mask].append(i)
else:
mask_dict[mask] = [i]