Sorting every string could be costly

use a character count method to calculate the key on the fly

(which require O(n),while sorting require O(nlogn), where n is the length of string)

```
chr_primes= [2, 3, 5, 7, 11, 13, 17,
19, 23, 29, 31, 37, 41, 43,
47, 53, 59, 61, 67, 71,
73, 79, 83, 89, 97, 101]
def getStrSig(s):
ord_a = ord('a')
hash = 1
for c in s:
hash *= chr_primes[ ord(c) - ord_a ]
return hash
```

then use the above function to calulate key in dict

```
a = getStrSig(s)
if a not in dic:
dic[a] = [s]
else:
dic[a].append(s)
```

for further optimization,

1、if you want to use dic[s] multiple times, don't just use dic[s] every time

because every time you use ,it will cost a map search.

you can store dic[s] in a local variable,

and use that local variable every time you need.

2、iterating over a dict is slower than iterating over a list.

If I was to optimize the code you write , it would be something like this:

```
def groupAnagrams(self, strs):
def getStrSig(s):
#your hash function
pass
dic = {}
result = []
for s in strs:
a = getStrSig(s)
if dic.has_key(a):
dic[a].append(s)
else:
arr = [s]
dic[a] = arr
result.append(arr)
for s in result:
s.sort()
return result
```