Last active
August 11, 2020 10:39
-
-
Save cyclecycle/6fac4b35c5467d397ec242a3f4bdf4db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import groupby | |
def groupby_(obj, key=None, to_lists=True): | |
sorted_ = sorted(obj, key=key) | |
grouped = groupby(sorted_, key) | |
if to_lists: | |
grouped = {k: list(g) for k, g in grouped} | |
return grouped | |
unique_theme_key = lambda mapping: (mapping['theme']['name']), mapping['theme']['group']) | |
grouped = groupby_(sent_theme_mappings, key=unique_theme_key) | |
for theme_key, group in grouped.items(): | |
# theme_key: (name, group) | |
# group: list of mappings corresponding to theme |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment