Is it possible to use 'groupby' asynchronously?

Chris Angelico rosuav at gmail.com
Thu Oct 6 11:57:54 EDT 2016


On Thu, Oct 6, 2016 at 11:09 PM, Frank Millman <frank at chagford.com> wrote:
> Hi all
>
> I have used itertools.groupby before, and I love it. I used it to process a
> csv file and 'break' on change of a particular field. It worked very well.
>
> Now I want to use it to process a database table. I can select the rows in
> the desired sequence with no problem. However, I am using asyncio, so I am
> reading the rows asynchronously.
>
> Before I spend hours trying to figure it out, can anyone confirm if this is
> doable at all, or is groupby not designed for this.

Most of itertools is going to assume synchronous iterables. However,
the docs give pure-Python equivalents for quite a few:

https://docs.python.org/3/library/itertools.html#itertools.groupby

You may be able to tweak that into an actual "itertools.agroupby" or
"aitertools.groupby".

ChrisA



More information about the Python-list mailing list