How to remove subset from a file efficiently?

fynali iladijas at
Sat Jan 14 10:31:29 CET 2006

    $ cat

    import psyco

    postpaid_file = open('/home/sajid/python/wip/stc/2/PSP0000333')
    outfile = open('/home/sajid/python/wip/stc/2/PSP-CBR.dat.psyco',

    barred = {}

    for number in open('/home/sajid/python/wip/stc/2/CBR0000333'):
        barred[number] = None # just add it as a key

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

    postpaid_file.close(); outfile.close()

    $ time ./

    real    0m24.293s
    user    0m22.633s
    sys     0m0.524s

Saves ~6 secs.


More information about the Python-list mailing list