How to remove subset from a file efficiently?

fynali iladijas at gmail.com
Thu Jan 12 14:54:02 EST 2006


The code it down to 5 lines!

    #!/usr/bin/python

    barred = set(open('/home/sajid/python/wip/CBR0000319.dat'))

    postpaid_file = open('/home/sajid/python/wip/PSP0000320.dat')
    outfile = open('/home/sajid/python/wip/PSP-CBR.dat', 'w')

    outfile.writelines(number for number in postpaid_file if number not
in barred)

    postpaid_file.close(); outfile.close()

Awesome! (-:  Thanks a ton Fredrik, Steve.

    $ time ./cleanup.py

    real    0m11.048s
    user    0m5.232s
    sys     0m0.584s

But there seem to be that discrepancy; will chk and update back here.

Thank you all once again.




More information about the Python-list mailing list