Last active
August 29, 2015 14:03
-
-
Save goldsmith/b24aaba5d0c11a9ef44e to your computer and use it in GitHub Desktop.
Revisions
-
goldsmith revised this gist
Jul 6, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ def group_by(col, hashfn=None): if not hashfn: hashfn = hash # builtin hash group = defaultdict(list) [group[hashfn(e)].append(e) for e in col] return group.values() -
goldsmith revised this gist
Jul 6, 2014 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,11 +4,11 @@ from collections import Counter, defaultdict def group_by(col, hashfn=None): if not hashfn: hashfn = hash # builtin hash group = defaultdict(list) [group(hashfn(e)).append(e) for e in col] return group.values() @@ -17,5 +17,5 @@ def anagram_hash(word): return tuple(sorted(Counter(word))) group_by(["hello", "foo", "olleh", "bar", "baz", "arb"], hashfn=anagram_hash) # [["hello", "olleh"], ["foo"], ["bar", "arb"], ["baz"]] -
goldsmith revised this gist
Jul 6, 2014 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ """ from collections import Counter, defaultdict def group_by(col, hash=None): if not hash: hash = lambda e: e.__hash__() @@ -11,8 +12,10 @@ def group_by(col, hash=None): return group.values() def anagram_hash(word): return tuple(sorted(Counter(word))) group_by(["hello", "foo", "olleh", "bar", "baz", "arb"], anagram_hash) # [["hello", "olleh"], ["foo"], ["bar", "arb"], ["baz"]] -
goldsmith created this gist
Jul 6, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ """ Write a program that takes a list of words and groups together the anagrams. """ from collections import Counter, defaultdict def group_by(col, hash=None): if not hash: hash = lambda e: e.__hash__() group = defaultdict(list) [group(hash(e)).append(e) for e in col] return group.values() def anagram_hash(word): return tuple(sorted(Counter(word))) group_by(["hello", "foo", "olleh", "bar", "baz", "arb"], anagram_hash) # [["hello", "olleh"], ["foo"], ["bar", "arb"], ["baz"]]