Created
September 11, 2022 11:21
-
-
Save codecakes/6b67cc086426c5201d9f79f454afe3e5 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 typing import Optional, List | |
from collections import defaultdict | |
from itertools import groupby | |
def grouped_anagram(anagram_arr: List[str]) -> List[List[str]]: | |
w_group = defaultdict(list) | |
for key_sum, word in groupby(anagram_arr, lambda w: sum(map(ord, w))): | |
w_group[key_sum] += list(word) | |
return list(w_group.values()) | |
print(grouped_anagram(["eat", "tea", "tan", "ate", "nat", "bat"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment