Filtering two files with uncommon column

Martin Blume mblume at socha.net
Fri Jan 18 07:29:20 EST 2008


"Madhur" schrieb
> I would like to know the best way of generating filter 
> of two files based upon the following condition
> [...]
>
Sounds like homework. Here some suggestions:

- for each file, create a dictionary (see help(dict)
in the python shell for details) and populate it with 
the values, so that e.g.
    d1['def'] = 'abc def hij'
(help("".split), perhaps help("".strip))

- for each key in the first dictionary, look whether
it exists in the second, if not, write the value (the 
line extracted in the first step) out.
(help(dict.iteritems), help(dict.has_key))
(Note that for 
    if a_dict.has_key("def"): pass
one can also write 
    if "def" in a_dict: pass
but you won't find this in the simple on-line help,
at least in my version)

HTH
Martin




More information about the Python-list mailing list