开发者

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

开发者 https://www.devze.com 2023-01-07 20:58 出处:网络
I don\'t need the laziness of itertools.groupby. I just want to group my list into a dict of lists as such:

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?


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消