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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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.