I made this for a programming challenge over on a site called hackthissite. This is my first attempt at python, please if you do take a look at my code, please show me where i could improve my code so i can get better at this language. Thanks and hope it works for you like it is supposed to
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | import sys
import Tkinter
from string import *
def Load_WordList():
wordList = open("wordlist.txt", "r")
wStr = wordList.read()
wList = split(wStr,"\n")
return wList
def compare(x,y):
x1=0
x2=0
y1= []
y2= []
j = ''
k = ''
for i in x:
x1 = ord(i)
y1.append(x1)
for i in y:
x2 = ord(i)
y2.append(x2)
y1.sort(key=int)
y2.sort(key=int)
for a in y1:
j += str(a)
for a in y2:
k += str(a)
if j == k:
return 1
else:
return 0
def Unscramble(Gword,Wlist):
answer = str()
for i in Gword:
for wl in Wlist:
Solved = compare(i,wl)
if Solved == 1:
answer += wl + ","
break
return answer
#b = Load_WordList()
def Clipboard(CopyPaste):
global winner
if CopyPaste == 'Paste':
words = []
root = Tkinter.Tk()
root.withdraw()
text = root.clipboard_get()
root.destroy()
text = split(text)
return text
if CopyPaste == 'Copy':
root = Tkinter.Tk()
root.withdraw()
root.clipboard_clear()
root.clipboard_append(winner)
root.destroy
def main():
global winner
wordnn = Clipboard('Paste')
wordnm = Load_WordList()
winner = Unscramble(wordnn,wordnm)
winner = winner[:-1]
print "Succesfully Unscrambled and Automatically Coppied to Clipboard"
Clipboard('Copy')
def intro():
print "Welcome to Garen's Anagram Solver",
print "\n\nPlease copy the words to the clipboard from Hackthissite and then press enter, \n\nThen the words will be unscrambled\n\n",
print "Then Automatically coppied back onto your clipboard \n\nwhere you may paste them back into the site\n\nThank you for using Garen's Anagram Solver!\n\n"
raw_input("<--Press any key to unscramble-->")
main()
intro()
|
Please have a look at my code as i a an inpired new python code writer and would love to learn as much as possible with this new language i am trying to learn.
thanks