Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import OrderedDict
- N = 2000
- WORDS = ["pool", "loco", "cool", "stain", "satin", "loop"] * N + ["pretty", "nice"]
- def get_anagrams_default_orddict(words=WORDS):
- normalized = [''.join(sorted(w)) for w in words]
- d = OrderedDict()
- for i, n in enumerate(normalized):
- val = words[i]
- try:
- d[n][1] += 1
- except KeyError:
- d[n] = [val, 0]
- return [v[0] for k, v in d.iteritems() if v[1] >= 1]
- if __name__ == '__main__':
- print("Finding the anagrams in words=", WORDS)
- print(get_anagrams_default_orddict())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement