def calc_top_level_networks(site):
    networks = list(
        site.network_set.order_by('prefixlen', 'ip_upper', 'ip_lower')
    )
    nq = Network.objects.filter(site=site)
    tlns = []
    while True:
        try:
            cur = networks.pop(0)
        except IndexError:
            break

        super_nets, sub_nets = calc_networks(cur, nq=nq)
        if not super_nets:
            tlns.append(cur)

        for sn in sub_nets:
            try:
                networks.remove(sn)
            except ValueError:
                pass  # The network might have a different site

    def ncmp(n1, n2):
        pd = n1.prefixlen - n2.prefixlen
        if pd != 0:
            return pd
        n_u_d = n1.ip_upper - n2.ip_upper
        if n_u_d != 0:
            return n_u_d
        return n2.ip_lower - n1.ip_lower

    #return sorted(tlns, cmp=lambda n1, n2: int(ncmp(n1, n2) % 2))
    return tlns
dataset/ETHPy150Open mozilla/inventory/core/network/utils.py/calc_top_level_networks/swapped operands of `-`