How to remove subset from a file efficiently?
fynali
iladijas at gmail.com
Sat Jan 14 03:45:48 EST 2006
$ cat cleanup.py
#!/usr/bin/python
postpaid_file = open('/home/oracle/stc/test/PSP0000333')
outfile = open('/home/oracle/stc/test/PSP-CBR.dat', 'w')
barred = {}
for number in open('/home/oracle/stc/test/CBR0000333'):
barred[number] = None # just add it as a key
outfile.writelines([number for number in postpaid_file if number
not in barred])
postpaid_file.close(); outfile.close()
--
$ time ./cleanup.py
real 0m31.007s
user 0m24.660s
sys 0m3.550s
Can we say that using generators & newer Python _is_ faster?
--
fynali
More information about the Python-list
mailing list