Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def checkForErrors(list, letter, valid=[]):
- for entry in list:
- tmp = []
- for i in entry:
- tmp.append(i)
- for l in letter:
- try:
- tmp.remove(l)
- except Exception as E:
- pass
- if len(tmp) == 0:
- valid.append(entry)
- return valid
- def validate(string):
- if string in combs:
- return False
- else:
- if string in dictionary:
- return True
- else:
- return False
- def loop(list, max, tolist=False, text="", n=0):
- for l in list:
- if tolist:
- if validate(text):
- combs.append(text)
- if n != max:
- loop(list, max, tolist, text + l, n+1)
- def processLine(line, dic):
- line = line.split("\n")[0].lower()
- if line != "":
- if len(line) <= max:
- dic.append(line)
- def readFile(filename, dic=[]):
- line = filename.readline()
- processLine(line, dic)
- while line:
- line = filename.readline()
- processLine(line, dic)
- filename.close()
- return dic
- text = input("Type Leters: (e.g. EAGB)\n").lower()
- if text == "" or text == " ":
- print("Wrong input")
- exit()
- print("Loading dictionary...")
- dicFile = open("german.dic", "r")
- dictionary = []
- max = len(text)
- dictionary = readFile(dicFile)
- print("Loaded dictionary.")
- # print(dictionary)
- print("Generating words...")
- # create list and fill with all avail combs
- combs = []
- for l in text:
- loop(text, len(text), True, l, 1)
- print("Generation completed.")
- print("Checking for Errors...")
- final = checkForErrors(combs, text)
- print("Done.")
- print("Result: {0}\n".format(len(final)))
- print(final)
- # for comb in combs:
- #
- # print(comb)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement