I am wondering what is correct way or better write this script?
I have create next function and second for in loop or is better way to write down ?
#!/usr/bin/env python3
def find_ip_on_firewall_host_dictonary(elm_IP,elm_IP_object,hosts_obj,sources_obj,create_host):
found_IP_obj = next((fw_host for fw_host in hosts_obj if fw_host == elm_IP),False)
if found_IP_obj:
sources_obj.append(found_IP_obj)
else:
create_host.append(elm_IP_object)
return sources_obj, create_host
def find_ip(elm_IP,elm_IP_object,hosts_obj,sources_obj,create_host):
found_IP = False
for fw_host in hosts_obj:
if fw_host == elm_IP:
sources_obj.append(fw_host)
found_IP = True
break
if found_IP == False:
create_host.append(elm_IP_object)
return sources_obj, create_host
hosts_obj= ["10.1.1.2","10.1.1.1","10.1.1.3"]
elm_IP = "10.1.1.1"
elm_IP_object = "10.1.1.1/32"
sources_obj= []
create_host= []
source_obj, create_host = find_ip_on_firewall_host_dictonary(elm_IP,elm_IP_object,hosts_obj,sources_obj,create_host)
print(sources_obj)