Skip to content

Instantly share code, notes, and snippets.

@laat
Created February 8, 2015 00:25
Show Gist options
  • Save laat/7b3d8dee3f50e9793638 to your computer and use it in GitHub Desktop.
Save laat/7b3d8dee3f50e9793638 to your computer and use it in GitHub Desktop.
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
@laat
Copy link
Author

laat commented Feb 8, 2015

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment