애너그램별로 그룹 생성
https://leetcode.com/problems/group-anagrams/
class Solution(object):
def groupAnagrams(self, strs):
"""
:type strs: List[str]
:rtype: List[List[str]]
"""
answer = dict()
for str_ in strs:
sort_str = ''.join(sorted(str_))
if sort_str in answer.keys():
answer[sort_str].append(str_)
else:
answer[sort_str] = [str_]
return answer.values()
Next what to do
1. collections.defaultdict(list)를 이용하여 KeyError를 해결하자. <- key 있는지 확인하는 것 자체가 시간이 오래 걸림