My LeetCode grinding. Trying to do a problem a day.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415
  1. class Solution:
  2. def groupAnagrams(self, strs):
  3. ana = dict()
  4. for s in strs:
  5. key = ''.join(sorted(s))
  6. if key in ana:
  7. ana[key].append(s)
  8. else:
  9. ana[key] = [s]
  10. return ana.values()
  11. s = Solution()
  12. print("Expected: [['ate', 'eat', 'tea'], ['nat', 'tan'], ['bat']]")
  13. print("Got:", s.groupAnagrams(["eat", "tea", "tan", "ate", "nat", "bat"]))