Good use for itertools.dropwhile and itertools.takewhile

Neil Cerutti neilc at norwich.edu
Wed Dec 5 17:11:22 CET 2012


On 2012-12-05, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Wed, Dec 5, 2012 at 7:34 AM, Neil Cerutti <neilc at norwich.edu> wrote:
>> Well, shoot! Then this is a job for groupby, not takewhile.
>
> The problem with groupby is that you can't just limit it to two groups.
>
>>>> prod_desc("CAPSICUM RED fresh from QLD")
> ['QLD', 'fresh from']
>
> Once you've got a false key from the groupby, you would need to
> pretend that any subsequent groups are part of the false group
> and tack them on.

Whoops! Yep, that was from the very beginning of the thread.

-- 
Neil Cerutti



More information about the Python-list mailing list