# 给定一个字符串数组，将字母异位词组合在一起。字母异位词指字母相同，但排列不同的字符串。
#
#  示例:
#
#  输入: ["eat", "tea", "tan", "ate", "nat", "bat"]
# 输出:
# [
#   ["ate","eat","tea"],
#   ["nat","tan"],
#   ["bat"]
# ]
#
#  说明：
#
#
#  所有输入均为小写字母。
#  不考虑答案输出的顺序。
#
#  Related Topics 哈希表 字符串


# leetcode submit region begin(Prohibit modification and deletion)
class Solution(object):
    def groupAnagrams(self, strs):
        # 1，baoli
        # 2，using hash table
        result_dict = {}
        for item in strs:
            keys = "".join(sorted(item))
            if keys not in result_dict:
                result_dict[keys] = [item]
            else:
                result_dict[keys].append(item)
        return list(result_dict.values())
# leetcode submit region end(Prohibit modification and deletion)
