Advertisement
Guest User

Untitled

a guest
May 28th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. from collections import OrderedDict
  2.  
  3. N = 2000
  4.  
  5. WORDS = ["pool", "loco", "cool", "stain", "satin", "loop"] * N + ["pretty", "nice"]
  6.  
  7. def get_anagrams_default_orddict(words=WORDS):
  8. normalized = [''.join(sorted(w)) for w in words]
  9. d = OrderedDict()
  10. for i, n in enumerate(normalized):
  11. val = words[i]
  12. try:
  13. d[n][1] += 1
  14. except KeyError:
  15. d[n] = [val, 0]
  16. return [v[0] for k, v in d.iteritems() if v[1] >= 1]
  17.  
  18. if __name__ == '__main__':
  19. print("Finding the anagrams in words=", WORDS)
  20. print(get_anagrams_default_orddict())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement