How to remove subset from a file efficiently?

fynali iladijas at gmail.com
Sat Jan 14 08:00:25 CET 2006


    $ cat cleanup_ray.py
    #!/usr/bin/python
    import itertools

    b = set(file('/home/sajid/python/wip/stc/2/CBR0000333'))

file('PSP-CBR.dat,ray','w').writelines(itertools.ifilterfalse(b.__contains__,file('/home/sajid/python/wip/stc/2/PSP0000333')))

    --
    $ time ./cleanup_ray.py

    real    0m5.451s
    user    0m4.496s
    sys     0m0.428s

(-: Damn!  That saves a bit more time!  Bravo!

Thanks to you Raymond.




More information about the Python-list mailing list