def subnet_case(ip, sn): assert util.subnet(ip) == sn
def num_subnets(alerts): by_dst = groupby(alerts, lambda a: subnet(a['ip_dst'])) return len(list(by_dst))