Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我不需要 itertools.groupby 的懒惰。我只想将我的列表分组为列表的字典,如下所示:
dict([(a, list(b)) for a,b in itertools.groupby(mylist, mykeyfunc)])
是否有一个标准功能已经这样做了?
不,标准库中不包含执行此操作的函数。
听起来您已经有了一个可以满足您需求的单行功能。用它。