Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64800

Re: Lists inside dictionary and how to look for particular value

From Gregory Ewing <greg.ewing@canterbury.ac.nz>
Newsgroups comp.lang.python
Subject Re: Lists inside dictionary and how to look for particular value
Date 2014-01-27 12:08 +1300
Message-ID <bklis1Fihb7U1@mid.individual.net> (permalink)
References <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com> <510d7811-729f-4cf5-b563-8094745293b3@googlegroups.com>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Lists inside dictionary and how to look for particular value mick verdu <mickverdu@gmail.com> - 2014-01-26 10:47 -0800
  Re: Lists inside dictionary and how to look for particular value Peter Otten <__peter__@web.de> - 2014-01-26 20:44 +0100
  Re: Lists inside dictionary and how to look for particular value Tim Chase <python.list@tim.thechases.com> - 2014-01-26 14:00 -0600
  Re: Lists inside dictionary and how to look for particular value mick verdu <mickverdu@gmail.com> - 2014-01-26 12:20 -0800
    Re: Lists inside dictionary and how to look for particular value Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-01-27 12:08 +1300
  Re: Lists inside dictionary and how to look for particular value Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-26 20:25 +0000
  Re: Lists inside dictionary and how to look for particular value mick verdu <mickverdu@gmail.com> - 2014-01-26 12:28 -0800
    Re: Lists inside dictionary and how to look for particular value mm0fmf <none@mailinator.com> - 2014-01-26 21:20 +0000
    Re: Lists inside dictionary and how to look for particular value Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-01-26 21:36 -0500
  Re: Lists inside dictionary and how to look for particular value mick verdu <mickverdu@gmail.com> - 2014-01-26 15:54 -0800
    Re: Lists inside dictionary and how to look for particular value Peter Otten <__peter__@web.de> - 2014-01-27 09:54 +0100

csiph-web