Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: Lists inside dictionary and how to look for particular value Date: Mon, 27 Jan 2014 12:08:47 +1300 Lines: 27 Message-ID: References: <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com> <510d7811-729f-4cf5-b563-8094745293b3@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net nhqefsQvAt/D1uqRImRLwAOY4n0JnWO0gnX/xeORZkM/z8aMo1 Cancel-Lock: sha1:kbZTqb5IrIAaRC/z5uIGHVzwEx0= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: <510d7811-729f-4cf5-b563-8094745293b3@googlegroups.com> Xref: csiph.com comp.lang.python:64800 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