解题思路:将数组的字符串的每个字符排序后的元组作为key,将key相同的字符串都放在一个数组中,key相同的字符串即字母异位的单词
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
visited = {}
for x in strs:
s = tuple(sorted(x))
if s not in visited:
visited[s] = [x]
else:
visited[s].append(x)
return list(visited.values())