Created
February 8, 2015 00:25
-
-
Save laat/7b3d8dee3f50e9793638 to your computer and use it in GitHub Desktop.
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 characters
from collections import defaultdict | |
liste = ["abc", "bca", "ab"] | |
grupper = defaultdict(list) | |
def hash(streng): | |
return ''.join(sorted(streng)) | |
for streng in liste: | |
grupper[hash(streng)].append(streng) | |
print grupper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
liste.append er O(1)
Hvis vi antar at ingen ord er lengre enn feks 30 karakterer er hash-funskjonen O(1)
loopen er O(n)