Find group of strings that are anagrams
<p>This question refers to <a href="http://www.lintcode.com/en/problem/anagrams/" rel="nofollow">this problem on lintcode</a>. I have a working solution, but it takes too long for the huge testcase. I am wondering how can it  be improved? Maybe I can decrease the number of comparisons I make in the outer loop.</p>

<pre><code>class Solution:
    # @param strs: A list of strings
    # @return: A list of strings
    def anagrams(self, strs):
        # write your code here
        ret=set()
        for i in range(0,len(strs)):
            for j in range(i+1,len(strs)):
                if i in ret and j in ret:
                    continue
                if Solution.isanagram(strs[i],strs[j]):
                    ret.add(i)
                    ret.add(j)

        return [strs[i] for i in list(ret)]


    @staticmethod
    def isanagram(s, t):
        if len(s)!=len(t):
            return False
        chars={}
        for i in s:
            if i in chars:
                chars[i]+=1
            else:
                chars[i]=1

        for i in t:
            if i not in chars:
                return False
            else:
                chars[i]-=1
                if chars[i]&lt;0:
                    return False

        for i in chars:
            if chars[i]!=0:
                return False
        return True
</code></pre>

<p><strong>Update:</strong> Just to add, not looking for built-in pythonic solutions such as using <code>Counter</code> which are already optimized. Have added Mike's suggestions, but still exceeding time-limit.</p>

<p>Why not this?    </p>

<pre><code>str1 = "cafe"
str2 = "face"
def isanagram(s1,s2):
    return all(sorted(list(str1)) == sorted(list(str2)))

if isanagram(str1, str2):
    print "Woo"
</code></pre>

python string anagram