Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1. def checkForErrors(list, letter, valid=[]):
  2.  
  3.     for entry in list:
  4.  
  5.         tmp = []
  6.  
  7.         for i in entry:
  8.             tmp.append(i)
  9.  
  10.         for l in letter:
  11.  
  12.             try:
  13.                 tmp.remove(l)
  14.  
  15.             except Exception as E:
  16.                 pass
  17.  
  18.  
  19.         if len(tmp) == 0:
  20.  
  21.             valid.append(entry)
  22.  
  23.     return valid
  24.  
  25.  
  26. def validate(string):
  27.  
  28.     if string in combs:
  29.         return False
  30.  
  31.     else:
  32.  
  33.         if string in dictionary:
  34.             return True
  35.         else:
  36.             return False
  37.  
  38.  
  39. def loop(list, max, tolist=False, text="", n=0):
  40.  
  41.     for l in list:
  42.         if tolist:
  43.             if validate(text):
  44.                 combs.append(text)
  45.         if n != max:
  46.             loop(list, max, tolist, text + l, n+1)
  47.  
  48.  
  49. def processLine(line, dic):
  50.  
  51.     line = line.split("\n")[0].lower()
  52.  
  53.     if line != "":
  54.         if len(line) <= max:
  55.             dic.append(line)
  56.  
  57.  
  58. def readFile(filename, dic=[]):
  59.  
  60.     line = filename.readline()
  61.     processLine(line, dic)
  62.  
  63.     while line:
  64.         line = filename.readline()
  65.         processLine(line, dic)
  66.  
  67.     filename.close()
  68.  
  69.     return dic
  70.  
  71.  
  72. text = input("Type Leters: (e.g. EAGB)\n").lower()
  73.  
  74. if text == "" or text == " ":
  75.     print("Wrong input")
  76.     exit()
  77.  
  78.  
  79. print("Loading dictionary...")
  80.  
  81. dicFile = open("german.dic", "r")
  82.  
  83. dictionary = []
  84. max = len(text)
  85.  
  86.  
  87. dictionary = readFile(dicFile)
  88.  
  89.  
  90. print("Loaded dictionary.")
  91. # print(dictionary)
  92. print("Generating words...")
  93. # create list and fill with all avail combs
  94. combs = []
  95.  
  96. for l in text:
  97.     loop(text, len(text), True, l, 1)
  98.  
  99. print("Generation completed.")
  100. print("Checking for Errors...")
  101. final = checkForErrors(combs, text)
  102.  
  103.  
  104. print("Done.")
  105. print("Result: {0}\n".format(len(final)))
  106.  
  107. print(final)
  108.  
  109. # for comb in combs:
  110. #
  111. #     print(comb)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement