dvogel
dvogel

Reputation: 420

Does python have a non-lazy version of itertools.groupby?

I don't need the laziness of itertools.groupby. I just want to group my list into a dict of lists as such:

dict([(a, list(b)) for a,b in itertools.groupby(mylist, mykeyfunc)])

Is there a standard function that already does this?

Upvotes: 5

Views: 628

Answers (2)

Will McCutchen
Will McCutchen

Reputation: 13117

No, there's not a function included in the standard library to do this.

Upvotes: 4

Ned Batchelder
Ned Batchelder

Reputation: 375814

It sounds like you have a one-line function already that does what you want. Use it.

Upvotes: -2

Related Questions