Snippets Collections
def anagramGrouping(words):
    groups_list = []
    sets_list = {}
    
    for word in words:
        new = frozenset(word)
        if (new in sets_list.keys()):
            sets_list[new].append(word)
        else:
            sets_list[new] = [word]
    
    for key in sets_list:
        groups_list.append(sets_list[key])
    
    return(groups_list)
star

Mon Feb 21 2022 18:08:38 GMT+0000 (Coordinated Universal Time)

#python #anagrams #frozenset #hashtable

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension