Question: https://oj.leetcode.com/problems/anagrams/
Question Name: Anagrams
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | class Solution: # @param strs, a list of strings # @return a list of strings def anagrams(self, strs): records = {} for string in strs: signature = "".join(sorted([i for i in string])) bucket = records.get(signature, []) bucket.append(string) records[signature] = bucket result = [] for bucket in records.values(): if len(bucket) > 1: # There are two or more strings, having the same # letter distribution. They are anagrams. result.extend(bucket) return result |