Efficient grep using Python?

P at draigBrady.com P at draigBrady.com
Wed Dec 15 17:10:08 CET 2004


sf wrote:
> Just started thinking about learning python.
> 
> Is there any place where I can get some free examples, especially for
> following kind of problem ( it must be trivial for those using python)
> 
> I have files A, and B each containing say 100,000 lines (each line=one
> string without any space)
> 
> I want to do
> 
> "  A  - (A intersection B)  "
> 
> Essentially, want to do efficient grep, i..e from A remove those lines which
> are also present in file B.

You could implement elegantly using the new sets feature
For reference here is the unix way to do it:

sort a b b | uniq -u

-- 
Pádraig Brady - http://www.pixelbeat.org
--



More information about the Python-list mailing list