[Tutor] How to show dictionary item non present on file

jarod_v6 at libero.it jarod_v6 at libero.it
Tue Jul 22 13:10:18 CEST 2014


Hin there!!!

I have a niave question on dictionary analysis: 
If you have a dictionary like this:
diz
Out[8]: {'elenour': 1, 'frank': 1, 'jack': 1, 'ralph': 1}

and you have a list and you want to know which  keys are not present on my 
dictionary the code are simple.
for i in diz.keys():
   ...:     if i in mitico:
   ...:         print "NO"
   ...:     else:
   ...:         print i
   ...:         
NO

But I havethis problem I have a file and I want to know which elements are not 
present on my file from dictionary.
 more data.tmp 
jack	1
pippo	1
luis	1
frate	1
livio	1
frank	1


with open("data.tmp") as p:
    for i in p:
        lines= i.strip("\n").split("\t")
        if not diz.has_key(lines[0]):
   ....:             print i
   ....:             
pippo	1

luis	1

frate	1

livio	1

The output I want is to have :
ralph and 'elenour.. how can I do this?
thanks in advance!



More information about the Tutor mailing list