human
I am working on the file "Python/leetcode/easy/strings-arrays.ipynb".
The first task is:
Q.6. Given an array of strings, group anagrams together.
Can you write Python program for it?

Write me a the Python program you requested?
assistant
#Here is the Python program you requested.

class Solution(object):
    def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
        """
        :type strs: List[str]
        :rtype: List[List[str]]
        
        Method: Build a dictionary of words creating a bag of characters representation.
                Generate a has for that representation and add words with a similar hash.
        """
        words = {}
        
        # Build a dictionary of words.
        for word in strs:
            boc_vec = [0 for i in range(26)]
            for char in word:
                boc_vec[ord(char) - 97] += 1

            # Check if the representation if present in the dict.
            hval = hash(tuple(boc_vec))
            if hval not in words:
                words[hval] = [word]
            else:
                words[hval].append(word)
        
        # Once, the dictionary is built, generate list.
        fin = []
        for key in words.keys():
            fin.append(words[key])
        
        return fin
        

print(Solution().groupAnagrams(["eat", "tea", "tan", "ate", "nat", "bat"]))