How to remove subset from a file efficiently?

Raymond Hettinger python at
Thu Jan 12 18:37:44 CET 2006

> I have two files:
>   - PSP0000320.dat (quite a large list of mobile numbers),
>   - CBR0000319.dat (a subset of the above, a list of barred bumbers)

# print all non-barred mobile phone numbers
barred = set(open('CBR0000319.dat'))
for num in open('PSP0000320.dat'):
    if num not in barred:
        print num,


More information about the Python-list mailing list