mick verdu wrote:
What I want is if host already exists it would
overwrite otherwise add to database. And if host doesn't exist it will first
add this host to database and then compare its IP with IPs of rest of hosts.
If ip matches with any of the other hosts, it will delete the host that it
just added now.

It sounds like you should be maintaining two dictionaries:

   hostname --> IP (+ other host-related data)

   IP --> hostname

Given a (newhost, newip) pair, first look for newip in the
IP --> hostname dictionary.

If it's there and the old hostname equals newhost, you're
finished.

If it's there with a different hostname, first delete
that entry from IP --> hostname, and also delete the
old hostname from hostname --> IP.

Now add tne new entry to both dictionaries.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to