Attachment 'test2.py'

Download

   1 letters=raw_input("letters> ")
   2 
   3 filein=open("linux.words","r")
   4 words=filein.readlines()
   5 words=[i.strip() for i in words if len(i)<=len(letters)+1]
   6 
   7 def countletters(word):
   8     word=word.lower()
   9     ret=[0]*26
  10     for i in word:
  11         n=ord(i)-97
  12         if (n>=0 and n<26) : ret[n]+=1
  13         else: return None
  14     return ret
  15 
  16 def cmp(a,b):
  17     for i in range(26):
  18         if a[i]<b[i] : return False
  19     return True
  20 
  21 lettfp=countletters(letters)
  22 
  23 answer=[]
  24 for i in words:
  25     try:
  26         if cmp(lettfp,countletters(i)) : answer.append(i)
  27     except: pass
  28 
  29 answer.sort(key=len)
  30 for i in answer: print i
  31 raw_input("")

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.