MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / groupAnagrams

Method groupAnagrams

Python/group_anagram.py:12–23  ·  view source on GitHub ↗

:type strs: List[str] :rtype: List[List[str]]

(self, strs)

Source from the content-addressed store, hash-verified

10
11class Solution(object):
12 def groupAnagrams(self, strs):
13 """
14 :type strs: List[str]
15 :rtype: List[List[str]]
16 """
17 from collections import defaultdict
18
19 anagrams = defaultdict(list)
20 for s in strs:
21 anagrams[str(sorted(s))].append(s)
22
23 return list(anagrams.values())
24
25n=["eat", "tea", "tan", "ate", "nat", "bat"]
26ans=Solution()

Callers 1

group_anagram.pyFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected