Hacker News new | ask | show | jobs
by t43562 1507 days ago
The shell's advantage is that of the pipeline components don't need to suck the whole file in so it can potentially operate on much larger files without running out of memory. I think only "sort" is problematic and at least it's a merge sort.

In Python you could use a generator but it would get a little more complicated and you'd still have to add all the words to set() but hopefully the number of different words is not that great.

The trie approach is quite memory efficient and that can matter.

1 comments

I'm fairly sure `open` is a generator and doesn't load the whole file into memory. So you wouldn't hit a memory error unless like you said the amount of unique words is high enough.
I think you're right but I believe that wrapping it in List(...) is where that would force the whole file into memory.
Yeah, you're right, that's my mistake.

I think you can just omit it but yeah...