class Solution:
    # @param {string[]} strs
    # @return {string[]}
    def anagrams(self, strs):
        if len(strs) == 1:
            return strs
        out = []
        dict = {''.join(sorted(s)):[] for s in strs}
        for s in strs:
            dict[''.join(sorted(s))].append(s)
        for el in dict:
            out.append(dict[el])
        return out

s = Solution()
x = ["an", "na"]
print s.anagrams(x)

bf968d0c8ea4e82fa812a82e3eb7fc85641e18ce
class Solution:
    # @param {string[]} strs
    # @return {string[]}
    def anagrams(self, strs):
        if len(strs) == 1:
            return strs
        out = []
        dict = {''.join(sorted(s)):[] for s in strs}
        for s in strs:
            dict[''.join(sorted(s))].append(s)
        for el in dict:
            out.append(dict[el])
        return out

s = Solution()
x = ["an", "na"]
print s.anagrams(x)
