Python Forum
set.difference of two list gives empty result
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
set.difference of two list gives empty result
#1
hi,

i want to get the difference from two list of strings (using sets) but i always get an empty result. funny enough this worked until today and stopped working overnight without me changing something.

the function:
def delete_dead_ips():
    # delete ip's that exists in netbox but not in aix registry
    aix_reg_list = []
    for i in net_info:
        address,mask,broadcast,dns_name = i.split('/')
        mask_cidr= IPv4Network(address + "/" + mask, strict=False).prefixlen
        addr_recalc = address + "/" + str(mask_cidr)
        aix_reg_list.append(addr_recalc)
    print('items in aix registry list: "%s"' % len(aix_reg_list))
    print('items in aix_ips (netbox) list: "%s"' % len(aix_ips))
    #print("\n".join(map(str, aix_reg_list)))
    #print("\n".join(map(str, aix_ips)))
    dead_ips = list(set(aix_ips).difference(set(aix_reg_list)))
    print('items in aix registry but not in netbox "%s"' % len(dead_ips))
    if dead_ips and aix_reg_list:
        logging.info('ips in netbox but not in aix registry removed: "%s"' % ",".join(dead_ips))
        for x in dead_ips:
            all_ips.remove(x)
            aix_ips.remove(x)
            try:
                bla = nb.ipam.ip_addresses.get(q=x)
                result = nb.ipam.ip_addresses.delete([bla])
            except pynetbox.core.query.RequestError as e:
                logging.error(str(e.error))
result:
Output:
root@nimvie: /root/bin # ./netbox_import.py 2022-06-14 12:56:47,148 [INFO] netbox 3.2 connected items in aix registry list: "1708" items in aix_ips (netbox) list: "1710" items in aix registry but not in netbox "0" -> this is clearly a lie
format of the lists (bog standard ip adresses):
['10.95.0.1/22', '10.95.0.1/22', '10.95.0.1/22', '10.95.0.1/22', '10.95.0.1/22', '10.95.0.1/22', '10.95.0.1/22', '10.95.0.1/22', '10.95.0.1/22', '10.95.0.1/22', '10.95.0.13/22', '10.95.0.119/22', '10.95.0.149/22', '10.95.0.211/22', '10.95.1.14/22', '10.95.1.15/22', '10.95.1.16/22', '10.95.1.18/22', '10.95.1.20/22', '10.95.1.21/22', '10.95.1.25/22', '10.95.1.48/22', '10.95.1.149/22', '10.111.160.6/24', '10.111.160.10/24']
any hints welcome, as i dont see a obvious reason for this....

wbr

chris
Reply


Messages In This Thread
set.difference of two list gives empty result - by wardancer84 - Jun-14-2022, 11:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  difference between forms of input a list to function akbarza 6 1,113 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  Code with empty list not executing adeana 9 3,802 Dec-11-2023, 08:27 AM
Last Post: buran
  displaying empty list vlearner 5 1,719 Jan-19-2022, 09:12 AM
Last Post: perfringo
  Remove empty keys in a python list python_student 7 3,110 Jan-12-2022, 10:23 PM
Last Post: python_student
  What is the value after JOINING an empty list? JaneTan 2 5,285 Jan-04-2021, 06:25 PM
Last Post: deanhystad
  What is the difference between a generator and a list comprehension? Pedroski55 2 2,263 Jan-02-2021, 04:24 AM
Last Post: Pedroski55
  Printing empty list? hhydration 2 2,151 Oct-28-2020, 11:34 AM
Last Post: Atekka
  Stop a function if the list it needs is empty Pedroski55 2 2,963 Jul-25-2020, 11:50 PM
Last Post: Pedroski55
  Need help to make an empty list with possibility to add Arnsol 1 1,841 Mar-19-2020, 06:08 PM
Last Post: michael1789
  list sum gives unexpected result Nesso 0 1,716 Feb-04-2020, 08:31 AM
Last Post: Nesso

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020