Given an array of strings, group anagrams together.
For example, given: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”],
Return:
[
[“ate”, “eat”,”tea”],
[“nat”,”tan”],
[“bat”]
]
Note:
For the return value, each inner list’s elements must follow the lexicographic order.
All inputs will be in lower-case.
class Solution(object):
def groupAnagrams(self,strs):
doc={}
count={}
list_=[]
if not len(strs):
return
for s in strs:
temp="".join(sorted(s))
if temp in doc:
doc[temp]+=[s]
else:
doc[temp]=[s]
print doc
for i in doc:
tmp=doc[i]
tmp.sort()
list_+=[tmp]
return list_