itertools.groupby

Chris Angelico rosuav at gmail.com
Mon Apr 22 11:14:39 EDT 2013


On Tue, Apr 23, 2013 at 12:49 AM, Oscar Benjamin
<oscar.j.benjamin at gmail.com> wrote:
> Iterators are
> typically preferred over list slicing for sequential text file access
> since you can avoid loading the whole file at once. This means that
> you can process a large file while only using a constant amount of
> memory.

And, perhaps even more importantly, allows you to pipe text in and
out. Obviously some operations (eg grep) lend themselves better to
this than do others (eg sort), but with this it ought at least to
output each group as it comes.

ChrisA



More information about the Python-list mailing list