Mirage
Mirage

Reputation: 31548

How can i generate the english words from given characters in python

In my django application the user will enter some characters in the text box and based on the characters i need to supply the common words from english dictionary and suggest that to the user.

Is ther any common english dictionary database available or some sort of api from any other site which can accomplish the task

Upvotes: 1

Views: 159

Answers (1)

wye.bee
wye.bee

Reputation: 716

It sounds like you are looking for a program that can find anagrams. Here is a non-django solution. It uses /usr/share/dict/words as suggested by Joel.

from collections import defaultdict

def canonical_form(word):
    return tuple(sorted(word))

anagrams = defaultdict(list)

for word in open("/usr/share/dict/words"):
    word = word.lower().strip()
    anagrams[canonical_form(word)].append(word)

while True:
    print anagrams[canonical_form(raw_input())]

Upvotes: 4

Related Questions