Hacker News new | ask | show | jobs
by DylanDmitri 2131 days ago
In loopless Python:

    set(open('file_b')) - set(open('file_a'))
Slower than J by a factor of 2-3, but still 10x faster than grep:

    real    0m0.128s
    user    0m0.078s
    sys     0m0.063s
This would make a good Rosetta Code prompt.
3 comments

I didn't know you could simply open a file and setify it. Interesting. & neat.
You can setify any iterable. File handles are iterables that return a line at a time. Tada!
> File handles are iterables...

I did not know that. Assumed you had to somehow wrap them first. Very useful, thanks!

this is cheeky, I like it
This is only fast because it hits C underneath, isn't it?