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


Groups > comp.lang.python > #64789

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

Path csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!feeder1.cambriumusenet.nl!feed.tweaknews.nl!85.12.40.138.MISMATCH!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'skip:[ 20': 0.04; 'detect': 0.07; 'hosts': 0.07; 'modify': 0.07; 'english,': 0.09; 'host,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'changes': 0.15; 'dict': 0.16; 'dictionary.': 0.16; 'hostname': 0.16; 'inputs': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'unambiguous': 0.16; 'wrote:': 0.18; 'input': 0.22; 'example': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'necessary.': 0.24; 'skip': 0.24; 'first,': 0.26; 'header:X-Complaints-To:1': 0.27; 'host': 0.29; 'matching': 0.30; "skip:' 10": 0.31; 'values.': 0.31; 'mac': 0.33; 'plain': 0.33; 'proceed': 0.33; 'problem': 0.35; 'add': 0.35; 'really': 0.36; 'should': 0.36; 'searching': 0.37; 'list': 0.37; 'list.': 0.37; 'e.g.': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'new': 0.61; 'making': 0.63; 'soon': 0.63; 'different': 0.65; '192.168.0.1': 0.84; 'subject:Lists': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Lists inside dictionary and how to look for particular value
Date Sun, 26 Jan 2014 20:44:21 +0100
Organization None
References <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p50849f45.dip0.t-ipconnect.de
User-Agent KNode/4.7.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6001.1390765477.18130.python-list@python.org> (permalink)
Lines 60
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1390765477 news.xs4all.nl 2967 [2001:888:2000:d::a6]:36435
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:64789

Show key headers only | View raw


mick verdu wrote:

> z={ 'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200'],
>     'PC3': ['03:03:03:03:03:03', '192.168.0.3', '200'],
>     'PC1': ['01:01:01:01:01:01', '192.168.0.1', '200'] }
> 
> My solution:
> 
> z=raw_input("Enter Host, Mac, ip and time")
> t=z.split()
> t[0]=z[1:]
> for key in dic:
>     if t[2] in dic[key]:
>         del dic[t[0]]
>     else:
>         dic[t[0]] = t[1:]
> 
> 
> What I really want to achieve is:
> 
> 
> How to search for a particular value inside list. First, I want the user
> to input hostname and ip. e.g. PC1 and 192.168.0.1, then need to find out
> if 192.168.0.1 has already been assigned to some host in dictionary. In
> this case I would need to skip for search inside list of user input host.
> 
> Forexample, if user inputs PC1 and 192.168.0.1 i would like to skip
> searching in above PC1's values. So it should detect matching only with
> different hosts and skip its own name.
> 
> If i input PC4 and 192.168.0.1 then it should detect conflict with PC1. So
> PC4 would be deleted(As soon as user inputs new host it is saved in above
> database then if conflict with others deleted)

You are making the problem unnecessarily complex. For the example scenario 
start with a dict that maps host to ip:

host2ip = {
 "PC1": "192.168.0.1",
 "PC2": "192.168.0.2",
 "PC3": "192.168.0.3",
}

host, ip = raw_input("Enter host and ip: ").split()
if host not in host2ip:
    print "adding", host
    host2ip[host] = ip
else:
    old_ip = host2ip[host]
    if old_ip == ip:
        print "no changes necessary"
    else:
        print "updating ip for", host, "from", old_ip, "to", ip
        host2ip[host] = ip


Then proceed and come up with an unambiguous description of what to do with 
mac and time in plain english, and add or modify data structures as 
necessary.

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