Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If all lines in the file are unique, memory usage stays constant after the first line is read.

A set by definition contains only unique items, that is all items in a set are different from each other.



If you're going from generator object (or any other lazy iterator, like the file object in this case) -> set object, there will be a memory usage increase with each additional line read.

What I meant is you could in theory process a generator and omit duplicates without any real memory usage (even with a file of millions of lines) by chaining generators together. This would be slower than a set but much more memory efficient.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: