49. Group Anagrams

Medium

Python Solution

class Solution:
    def groupAnagrams(self, strs):
        container = {}
        for word in strs:
            sorted_word = str(''.join(sorted(word))) # soring the word and converting it to string
            if sorted_word not in container.keys(): # if the sorted word is not in the container, add it to the container and because of that we are able to group the anagrams
                container[sorted_word] = [word]
            else:
                container[sorted_word].append(word)

        return container.values()

Explanation

read the fucking comments