Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'mrab': 0.05; 'output': 0.05; 'skip:\xa0 30': 0.05; '21,': 0.07; 'skip:" 60': 0.07; 'subject:two': 0.07; 'sys': 0.07; '34,': 0.09; 'skip:o 50': 0.09; 'python': 0.11; '46,': 0.16; '54,': 0.16; 'address)': 0.16; 'count.': 0.16; 'dict': 0.16; 'dictionaries': 0.16; 'dictionary.': 0.16; 'help?': 0.16; 'hostname': 0.16; 'intersection': 0.16; 'subject:compare': 0.16; 'subject:dictionaries': 0.16; '\xa0print': 0.16; 'wrote:': 0.18; 'all,': 0.19; 'trying': 0.19; 'import': 0.22; 'print': 0.22; '31,': 0.24; 'entries': 0.24; 'compare': 0.26; 'code:': 0.26; 'values': 0.27; 'header:In-Reply- To:1': 0.27; 'tried': 0.27; 'am,': 0.29; '8bit%:3': 0.30; 'matching': 0.30; 'skip:( 40': 0.30; 'subject:list': 0.30; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; "skip:' 10": 0.31; '25,': 0.31; 'doc': 0.31; 'keys': 0.31; 'skip:& 70': 0.31; 'skip:( 50': 0.31; 'fri,': 0.33; 'to:name:python-list': 0.33; 'skip:d 20': 0.34; 'problem': 0.35; 'created': 0.35; 'skip:s 30': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'set.': 0.36; 'thanks': 0.36; 'skip:4 10': 0.37; 'two': 0.37; 'list': 0.37; '(i.e.,': 0.38; 'skip:m 40': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; '12,': 0.39; 'skip:8 10': 0.39; 'to:addr:python.org': 0.39; 'address.': 0.39; 'skip:- 60': 0.39; 'either': 0.39; 'skip:x 10': 0.40; 'skip:o 30': 0.61; 'address': 0.63; 'dear': 0.65; 'between': 0.67; 'below:': 0.68; 'containing': 0.69; 'skip:a 40': 0.72; 'difference.': 0.84; '212': 0.91; '212,': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=+l4cEr/k7uZiz6OELA25UaJXToAKt3wYV8qGO22GsI4=; b=PRetcp8/gNQiWgj3er5pMbkuGUKPN+yCd45KNs88A1s8SUcmypmwW/CESh+hs9Qbr3 dVqPETr5uiI2TPWJ/0bdqocjcFH+aAF9eokQj6Z+4NVCckKDvgs92XTj5NQXcfwynOOg hlcth4hQP3AsyK9ZR1gD74hgo6QbVcwF4sp+9n6gwWmhxwMTjRa9TnLNyJMxX1KirLa1 hRNeqlvmFw0v+lSDcCGWbUaYA2WdkPwnfVgY2AGl1FsLGQG4hJmjqaRZPbSjnrbHNEEC xnL5rLh3lZcx/XK1Xf5L5a93TxQ+41agyL7Uf+AVM9f4HXHfTWw9NrNfrgIa+lJsxDgZ iezg== MIME-Version: 1.0 X-Received: by 10.194.93.3 with SMTP id cq3mr10148279wjb.26.1380853766278; Thu, 03 Oct 2013 19:29:26 -0700 (PDT) In-Reply-To: <524DBB0B.3080008@mrabarnett.plus.com> References: <524DBB0B.3080008@mrabarnett.plus.com> Date: Fri, 4 Oct 2013 07:59:26 +0530 Subject: Re: compare two list of dictionaries From: Mohan L To: python-list Content-Type: multipart/alternative; boundary=047d7bb0482239d44f04e7e112eb 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: 671 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380853774 news.xs4all.nl 15963 [2001:888:2000:d::a6]:42005 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:55452 --047d7bb0482239d44f04e7e112eb Content-Type: text/plain; charset=ISO-8859-1 On Fri, Oct 4, 2013 at 12:14 AM, MRAB wrote: > On 03/10/2013 17:11, Mohan L wrote: > >> Dear All, >> >> I have two list of dictionaries like below: >> >> In the below dictionaries the value of ip can be either hostname or ip >> address. >> >> output1=[ >> {'count': 3 , 'ip': 'xxx.xx.xxx.1'}, >> {'count': 4, 'ip': 'xxx.xx.xxx.2'}, >> {'count': 8, 'ip': 'xxx.xx.xxx.3'}, >> {'count': 10, 'ip': 'xxx.xx.xxx.4'}, >> {'count': 212, 'ip': 'hostname1'}, >> {'count': 27, 'ip': 'hostname2'}, >> {'count': 513, 'ip': 'hostname3'}, >> {'count': 98, 'ip': 'hostname4'}, >> {'count': 1, 'ip': 'hostname10'}, >> {'count': 2, 'ip': 'hostname8'}, >> {'count': 3, 'ip': 'xxx.xx.xxx.11'}, >> {'count': 90, 'ip': 'xxx.xx.xxx.12'}, >> {'count': 12, 'ip': 'xxx.xx.xxx.13'}, >> {'count': 21, 'ip': 'xxx.xx.xxx.14'}, >> {'count': 54, 'ip': 'xxx.xx.xxx.15'}, >> {'count': 34, 'ip': 'xxx.xx.xxx.16'}, >> {'count': 11, 'ip': 'xxx.xx.xxx.17'}, >> {'count': 2, 'ip': 'xxx.xx.xxx.18'}, >> {'count': 19, 'ip': 'xxx.xx.xxx.19'}, >> {'count': 21, 'ip': 'xxx.xx.xxx.20'}, >> {'count': 25, 'ip': 'xxx.xx.xxx.21'}, >> {'count': 31, 'ip': 'xxx.xx.xxx.22'}, >> {'count': 43, 'ip': 'xxx.xx.xxx.23'}, >> {'count': 46, 'ip': 'xxx.xx.xxx.24'}, >> {'count': 80, 'ip': 'xxx.xx.xxx.25'}, >> {'count': 91, 'ip': 'xxx.xx.xxx.26'}, >> {'count': 90, 'ip': 'xxx.xx.xxx.27'}, >> {'count': 10, 'ip': 'xxx.xx.xxx.28'}, >> {'count': 3, 'ip': 'xxx.xx.xxx.29'}] >> >> >> In the below dictionaries have either hostname or ip or both. >> >> output2=( >> >> {'hostname': 'INNCHN01', 'ip_addr': 'xxx.xx.xxx.11'}, >> {'hostname': 'HYDRHC02', 'ip_addr': 'xxx.xx.xxx.12'}, >> {'hostname': 'INNCHN03', 'ip_addr': 'xxx.xx.xxx.13'}, >> {'hostname': 'MUMRHC01', 'ip_addr': 'xxx.xx.xxx.14'}, >> {'hostname': 'n/a', 'ip_addr': 'xxx.xx.xxx.15'}, >> {'hostname': 'INNCHN05', 'ip_addr': 'xxx.xx.xxx.16'}, >> {'hostname': 'hostname1', 'ip_addr': 'n/a'}, >> {'hostname': 'hostname2', 'ip_addr': 'n/a'}, >> {'hostname': 'hostname10', 'ip_addr': ''}, >> {'hostname': 'hostname8', 'ip_addr': ''}, >> {'hostname': 'hostname200', 'ip_addr': 'xxx.xx.xxx.200'}, >> {'hostname': 'hostname300', 'ip_addr': 'xxx.xx.xxx.400'}, >> >> ) >> >> trying to get the following difference from the above dictionary >> >> 1). compare the value of 'ip' in output1 dictionary with either >> 'hostname' and 'ip_addr' output2 dictionary and print their >> intersection. Tried below code: >> >> >> for doc in output1: >> for row in output2: >> if((row["hostname"] == doc["ip"]) or (row["ip_addr"] == >> doc["ip"])): >> print doc["ip"],doc["count"] >> >> *output:* >> >> hostname1 212 >> hostname2 27 >> hostname10 1 >> hostname8 2 >> xxx.xx.xxx.11 3 >> xxx.xx.xxx.12 90 >> xxx.xx.xxx.13 12 >> xxx.xx.xxx.14 21 >> xxx.xx.xxx.15 54 >> xxx.xx.xxx.16 34 >> >> 1. Create a dict from output1 in which the key is the ip and the value > is the count. > > 2. Create a set from output2 containing all the hostnames and ip_addrs. > > 3. Get the intersection of the keys of the dict with the set. > > 4. Print the entries of the dict for each member of the intersection. > > > 2). need to print the below output if the value of 'ip' in output1 >> dictionary is not there in in output2 dictionary(ip/hostname which is >> there in output1 and not there in output2): >> >> xxx.xx.xxx.1 3 >> xxx.xx.xxx.2 4 >> xxx.xx.xxx.3 8 >> xxx.xx.xxx.4 10 >> hostname3 513 >> hostname4 98 >> xxx.xx.xxx.17 11 >> xxx.xx.xxx.18 2 >> xxx.xx.xxx.19 19 >> xxx.xx.xxx.20 21 >> xxx.xx.xxx.21 25 >> xxx.xx.xxx.22 31 >> xxx.xx.xxx.23 43 >> xxx.xx.xxx.24 46 >> xxx.xx.xxx.25 80 >> xxx.xx.xxx.26 91 >> xxx.xx.xxx.27 90 >> xxx.xx.xxx.28 10 >> xxx.xx.xxx.29 3 >> >> 1. Get the difference between the keys of the dict and the intersection. > > 2. Print the entries of the dict for each member of the difference. #!/bin/env python import sys output1=[ {'count': 3 , 'ip': 'xxx.xx.xxx.1'}, {'count': 4, 'ip': 'xxx.xx.xxx.2'}, {'count': 8, 'ip': 'xxx.xx.xxx.3'}, {'count': 10, 'ip': 'xxx.xx.xxx.4'}, {'count': 212, 'ip': 'hostname1'}, {'count': 27, 'ip': 'hostname2'}, {'count': 513, 'ip': 'hostname3'}, {'count': 98, 'ip': 'hostname4'}, {'count': 1, 'ip': 'hostname10'}, {'count': 2, 'ip': 'hostname8'}, {'count': 3, 'ip': 'xxx.xx.xxx.11'}, {'count': 90, 'ip': 'xxx.xx.xxx.12'}, {'count': 12, 'ip': 'xxx.xx.xxx.13'}, {'count': 21, 'ip': 'xxx.xx.xxx.14'}, {'count': 54, 'ip': 'xxx.xx.xxx.15'}, {'count': 34, 'ip': 'xxx.xx.xxx.16'}, {'count': 11, 'ip': 'xxx.xx.xxx.17'}, {'count': 2, 'ip': 'xxx.xx.xxx.18'}, {'count': 19, 'ip': 'xxx.xx.xxx.19'}, {'count': 21, 'ip': 'xxx.xx.xxx.20'}, {'count': 25, 'ip': 'xxx.xx.xxx.21'}, {'count': 31, 'ip': 'xxx.xx.xxx.22'}, {'count': 43, 'ip': 'xxx.xx.xxx.23'}, {'count': 46, 'ip': 'xxx.xx.xxx.24'}, {'count': 80, 'ip': 'xxx.xx.xxx.25'}, {'count': 91, 'ip': 'xxx.xx.xxx.26'}, {'count': 90, 'ip': 'xxx.xx.xxx.27'}, {'count': 10, 'ip': 'xxx.xx.xxx.28'}, {'count': 3, 'ip': 'xxx.xx.xxx.29'}] output2=(('INNCHN01','xxx.xx.xxx.11'), ('HYDRHC02', 'xxx.xx.xxx.12'), ('INNCHN03','xxx.xx.xxx.13'), ('MUMRHC01','xxx.xx.xxx.14'), ('n/a','xxx.xx.xxx.15'), ('INNCHN05','xxx.xx.xxx.16'), ('hostname1','n/a'), ('hostname2','n/a'), ('hostname10',''), ('hostname8',''), ('hostname200','xxx.xx.xxx.200'), ('hostname300','xxx.xx.xxx.400'), ) ## 1). ## Create a dict from output1 in which the key is the ip and the value is the count. mongodb_data={} for doc in output1: mongodb_data.update({doc['ip']:doc['count']}) ## Create a set from output2 containing all the hostnames and ip_addrs. all_hostname_ip_set=set(list(sum(output2, ()))) ## Get the intersection of the keys of the dict with the set. key_set=set(mongodb_data.keys()) int_keys=key_set & all_hostname_ip_set # Print the entries of the dict for each member of the intersection. print "-------------------intersection-----------------------------" for key in int_keys: print key,mongodb_data[key] ## 2). ## Get the difference between the keys of the dict and the intersection. deff_keys=key_set - all_hostname_ip_set ## Print the entries of the dict for each member of the difference. print "-------------------difference-------------------------------" for key in deff_keys: print key,mongodb_data[key] $ ./demo.py -------------------intersection----------------------------- xxx.xx.xxx.11 3 xxx.xx.xxx.12 90 xxx.xx.xxx.13 12 xxx.xx.xxx.14 21 xxx.xx.xxx.15 54 xxx.xx.xxx.16 34 hostname2 27 hostname1 212 hostname10 1 hostname8 2 -------------------difference------------------------------- xxx.xx.xxx.29 3 xxx.xx.xxx.28 10 xxx.xx.xxx.17 11 xxx.xx.xxx.18 2 xxx.xx.xxx.19 19 xxx.xx.xxx.23 43 xxx.xx.xxx.22 31 xxx.xx.xxx.25 80 xxx.xx.xxx.24 46 xxx.xx.xxx.27 90 xxx.xx.xxx.26 91 xxx.xx.xxx.2 4 xxx.xx.xxx.21 25 hostname3 513 hostname4 98 xxx.xx.xxx.4 10 xxx.xx.xxx.20 21 xxx.xx.xxx.1 3 xxx.xx.xxx.3 8 > > > 3). Ip address with is there only in output2 dictionary. >> >> xxx.xx.xxx.200 >> xxx.xx.xxx.400 >> >> 1. Create a set from output2 containing all the ip_addrs > 2. Get the difference between the set and the keys of the dict created > from output1. I have one problem here. I want to compare the output2 (hostname or ip address) with output1 'ip' values (i.e., either hostname or ip address of output2 does not matching the ip dict key in output1 then I want to print either hostname or ip address from output2). Any help? Thanks for your time. Thanks Mohan L --047d7bb0482239d44f04e7e112eb Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Fri, Oct 4, 2013 at 12:14 AM, MRAB= <python@mrabarnett.plus.com> wrote:
On 03/10/2013 17:11, Moh= an L wrote:
Dear All,

I have two list of dictionaries like below:

In the below dictionaries the value of ip can be either hostname or ip
address.

output1=3D[
{'count': 3 , 'ip': 'xxx.xx.xxx.1'},
{'count': 4, 'ip': 'xxx.xx.xxx.2'},
{'count': 8, 'ip': 'xxx.xx.xxx.3'},
{'count': 10, 'ip': 'xxx.xx.xxx.4'},
{'count': 212, 'ip': 'hostname1'},
{'count': 27, 'ip': 'hostname2'},
{'count': 513, 'ip': 'hostname3'},
{'count': 98, 'ip': 'hostname4'},
{'count': 1, 'ip': 'hostname10'},
{'count': 2, 'ip': 'hostname8'},
{'count': 3, 'ip': 'xxx.xx.xxx.11'},
{'count': 90, 'ip': 'xxx.xx.xxx.12'},
{'count': 12, 'ip': 'xxx.xx.xxx.13'},
{'count': 21, 'ip': 'xxx.xx.xxx.14'},
{'count': 54, 'ip': 'xxx.xx.xxx.15'},
{'count': 34, 'ip': 'xxx.xx.xxx.16'},
{'count': 11, 'ip': 'xxx.xx.xxx.17'},
{'count': 2, 'ip': 'xxx.xx.xxx.18'},
{'count': 19, 'ip': 'xxx.xx.xxx.19'},
{'count': 21, 'ip': 'xxx.xx.xxx.20'},
{'count': 25, 'ip': 'xxx.xx.xxx.21'},
{'count': 31, 'ip': 'xxx.xx.xxx.22'},
{'count': 43, 'ip': 'xxx.xx.xxx.23'},
{'count': 46, 'ip': 'xxx.xx.xxx.24'},
{'count': 80, 'ip': 'xxx.xx.xxx.25'},
{'count': 91, 'ip': 'xxx.xx.xxx.26'},
{'count': 90, 'ip': 'xxx.xx.xxx.27'},
{'count': 10, 'ip': 'xxx.xx.xxx.28'},
{'count': 3, 'ip': 'xxx.xx.xxx.29'}]


In the below dictionaries have either hostname or ip or both.

output2=3D(

{'hostname': 'INNCHN01', 'ip_addr': 'xxx.xx.xxx= .11'},
{'hostname': 'HYDRHC02', 'ip_addr': 'xxx.xx.xxx= .12'},
{'hostname': 'INNCHN03', 'ip_addr': 'xxx.xx.xxx= .13'},
{'hostname': 'MUMRHC01', 'ip_addr': 'xxx.xx.xxx= .14'},
{'hostname': 'n/a', 'ip_addr': 'xxx.xx.xxx.15&#= 39;},
{'hostname': 'INNCHN05', 'ip_addr': 'xxx.xx.xxx= .16'},
{'hostname': 'hostname1', 'ip_addr': 'n/a'}= ,
{'hostname': 'hostname2', 'ip_addr': 'n/a'}= ,
{'hostname': 'hostname10', 'ip_addr': ''},<= br> {'hostname': 'hostname8', 'ip_addr': ''}, {'hostname': 'hostname200', 'ip_addr': 'xxx.xx.= xxx.200'},
{'hostname': 'hostname300', 'ip_addr': 'xxx.xx.= xxx.400'},

)

trying to get the following difference from the above dictionary

1). compare the value of 'ip' in output1 dictionary with either
'hostname' and 'ip_addr' output2 dictionary and print their=
intersection. Tried below code:


for doc in output1:
=A0 =A0 =A0 =A0 =A0for row in output2:
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if((row["hostname"] =3D=3D doc= ["ip"]) or (row["ip_addr"] =3D=3D
doc["ip"])):
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0print doc["ip"= ],doc["count"]

*output:*

hostname1 212
hostname2 27
hostname10 1
hostname8 2
xxx.xx.xxx.11 3
xxx.xx.xxx.12 90
xxx.xx.xxx.13 12
xxx.xx.xxx.14 21
xxx.xx.xxx.15 54
xxx.xx.xxx.16 34

1. Create a dict from output1 in which the key is the ip and the value
is the count.

2. Create a set from output2 containing all the hostnames and ip_addrs.

3. Get the intersection of the keys of the dict with the set.

4. Print the entries of the dict for each member of the intersection.


2). need to print the below output if the value of 'ip' in output1<= br> dictionary is not there in in output2 dictionary(ip/hostname which is
there in output1 and not there in output2):

=A0 xxx.xx.xxx.1 3
=A0 xxx.xx.xxx.2 4
=A0 xxx.xx.xxx.3 =A08
=A0 xxx.xx.xxx.4 =A010
=A0 hostname3 =A0513
=A0 hostname4 =A098
=A0 xxx.xx.xxx.17 =A011
=A0 xxx.xx.xxx.18 =A02
=A0 xxx.xx.xxx.19 =A019
=A0 xxx.xx.xxx.20 =A021
=A0 xxx.xx.xxx.21 =A025
=A0 xxx.xx.xxx.22 =A031
=A0 xxx.xx.xxx.23 =A043
=A0 xxx.xx.xxx.24 =A046
=A0 xxx.xx.xxx.25 =A080
=A0 xxx.xx.xxx.26 =A091
=A0 xxx.xx.xxx.27 =A090
=A0 xxx.xx.xxx.28 =A010
=A0 xxx.xx.xxx.29 =A03

1. Get the difference between the keys of the dict and the intersection.
2. Print the entries of the dict for each member of the difference.


#!/bin/env python
import s= ys


output1=3D[
{'count': 3 , 'ip': 'xxx.xx.xxx.1&= #39;},
{'co= unt': 4, 'ip': 'xxx.xx.xxx.2'},
{'count': = 8, 'ip': 'xxx.xx.xxx.3'},
{'co= unt': 10, 'ip': 'xxx.xx.xxx.4'},
{'count': = 212, 'ip': 'hostname1'},
{'co= unt': 27, 'ip': 'hostname2'},
{'count': 513= , 'ip': 'hostname3'},
{'co= unt': 98, 'ip': 'hostname4'},
{'count': 1, = 'ip': 'hostname10'},
{'co= unt': 2, 'ip': 'hostname8'},
{'count': 3, &= #39;ip': 'xxx.xx.xxx.11'},
{'co= unt': 90, 'ip': 'xxx.xx.xxx.12'},
{'count':= 12, 'ip': 'xxx.xx.xxx.13'},
{'co= unt': 21, 'ip': 'xxx.xx.xxx.14'},
{'count':= 54, 'ip': 'xxx.xx.xxx.15'},
{'co= unt': 34, 'ip': 'xxx.xx.xxx.16'},
{'count':= 11, 'ip': 'xxx.xx.xxx.17'},
{'co= unt': 2, 'ip': 'xxx.xx.xxx.18'},
{'count': = 19, 'ip': 'xxx.xx.xxx.19'},
{'co= unt': 21, 'ip': 'xxx.xx.xxx.20'},
{'count':= 25, 'ip': 'xxx.xx.xxx.21'},
{'co= unt': 31, 'ip': 'xxx.xx.xxx.22'},
{'count':= 43, 'ip': 'xxx.xx.xxx.23'},
{'co= unt': 46, 'ip': 'xxx.xx.xxx.24'},
{'count':= 80, 'ip': 'xxx.xx.xxx.25'},
{'co= unt': 91, 'ip': 'xxx.xx.xxx.26'},
{'count':= 90, 'ip': 'xxx.xx.xxx.27'},
{'co= unt': 10, 'ip': 'xxx.xx.xxx.28'},
{'count':= 3, 'ip': 'xxx.xx.xxx.29'}]



output2=3D(('INNCHN01','xxx.xx.xxx.11'),
<= div class=3D"gmail_default">('HYD= RHC02', 'xxx.xx.xxx.12'),
('IN= NCHN03','xxx.xx.xxx.13'),
('MUMRHC01','xxx.xx.x= xx.14'),
('n/= a','xxx.xx.xxx.15'),
<= font face=3D"courier new, monospace">('INNCHN05','xxx.xx.xxx.16= '),
('ho= stname1','n/a'),
('hostname2','n/a'),
('ho= stname10',''),
('hostname8',''),
('hostname200','xxx.xx.xx= x.200'),
('hostname300','xxx.xx.xxx.400'),
)=
## 1).
## Creat= e a dict from output1 in which the key is the ip and the value is the count= .
mongodb_data=3D{}
fo= r doc in output1:
=A0 =A0 =A0 =A0 mongodb_data.update({doc['ip'= ]:doc['count']})

## Create a set from output2 containing all the hostnames and ip_addrs.
all_host= name_ip_set=3Dset(list(sum(output2, ())))

## Get the intersection of the keys o= f the dict with the set.
key_set=3Dset(mongodb_data.keys())
int_keys=3Dkey_set & all_hostname= _ip_set
# Print the entries of the dict for each member of the intersec= tion.
print &q= uot;-------------------intersection-----------------------------"
= for key in int_keys:
=A0 =A0 = =A0 =A0 print key,mongodb_data[key]

## 2).
## Get t= he difference between the keys of the dict and the intersection.
deff_k= eys=3Dkey_set - all_hostname_ip_set
## Print= the entries of the dict for each member of the difference.
print "= ;-------------------difference-------------------------------"<= /div>
for key = in deff_keys:
=A0 =A0 print key,mongodb_data[key]

$ ./demo.py

-------------------intersection-----------------------------
xxx.x= x.xxx.11 3
xxx.xx.x= xx.12 90
xxx.xx.xxx.13 12
xxx.xx.xxx.14 21
xxx.xx.x= xx.15 54
xxx.xx.xxx.16 34
hostname2 27
hostname= 1 212
hostname10 1
hostname8 2
--------= -----------difference-------------------------------
xxx.xx.xxx.29 3
xxx.xx.x= xx.28 10
xxx.xx.xxx.17 11
xxx.xx.xxx.18 2
xxx.xx.x= xx.19 19
xxx.xx.xxx.23 43
xxx.xx.xxx.22 31
xxx.xx.x= xx.25 80
xxx.xx.xxx.24 46
xxx.xx.xxx.27 90
xxx.xx.x= xx.26 91
xxx.xx.xxx.2 4
xxx.xx.xxx.21 25
hostname= 3 513
hostname4 98
xxx.xx.xxx.4 10
xxx.xx.x= xx.20 21
xxx.xx.xxx.1 3
xxx.xx.xxx.3 8
=A0
=A0


3). Ip address with is there only in output2 dictionary.

xxx.xx.xxx.200
xxx.xx.xxx.400

1. Create a set from output2 containing all the ip_addrs

2. Get the difference between the set and the keys of the dict created
from output1.

I have one= problem here. =A0I want to compare the output2 (hostname or ip address) wi= th output1 'ip' values (i.e., either hostname or ip address of outp= ut2 does not matching the ip dict key in output1 =A0then I want to print ei= ther hostname or ip address from output2). =A0

Any help?

Thanks for your time.

Thanks
Mohan= L
--047d7bb0482239d44f04e7e112eb--