Skip to content

Instantly share code, notes, and snippets.

@minusworld
Created July 28, 2021 04:14
Show Gist options
  • Select an option

  • Save minusworld/e1af6570d57132963ec49ccfade9764b to your computer and use it in GitHub Desktop.

Select an option

Save minusworld/e1af6570d57132963ec49ccfade9764b to your computer and use it in GitHub Desktop.
from collections import defaultdict
def group(items: List[Any], key: Callable[[Any], Any]) -> Dict[Any, Any]:
dd = defaultdict(list)
for item in items:
k = key(item)
dd[k].append(item)
return dd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment