## solution 1: fast enough response, simple function, fail fast
from time import clock
def isanaword(k,s):
""" goes through the letters of second word (s) and returns it
if first word (k) contains exactly same letters in same number
"""
for c in s:
pos = k.find(c)
if pos==-1: return "" ## letter not contained in first one found
k = k[:pos]+k[pos+1:] ## drop the letter in found position pos by slicing
if not k: return s ## if all letters used, full anagram
if __name__=="__main__":
print('To quit enter empty line')
inputword=' '
while inputword:
inputword=raw_input('Give word: ')
if inputword:
t=clock()
for wd in [w.rstrip()
for w in open('words.txt')
if (len(w) == len(inputword)+1 ## newline longer
and isanaword(w.rstrip(),inputword))]:
print wd,
print
print 'Took %i ms'%((clock()-t)*1000)
marcelocent 0 Newbie Poster
sneekula 969 Nearly a Posting Maven
marcelocent commented: win7 +0
sneekula 969 Nearly a Posting Maven
marcelocent 0 Newbie Poster
TrustyTony 888 pyMod Team Colleague Featured Poster
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
marcelocent 0 Newbie Poster
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.