uccjshrimpton

Hex Word Finder

May 5th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. """
  2. Hex Word Finder
  3.  
  4. This program searches a text file for any words that are made up entirely of the letters available in HEX, ABCDEFG.
  5.  
  6. """
  7.  
  8. filename = input("Please enter the name of a text file and it's location if it is not in the root directory. You don't need to write '.txt'.\n")
  9. dictionary = open(filename+".txt","r")
  10.  
  11. currword = []
  12. lensixwords = []
  13. allhexwords = []
  14.  
  15. for char in dictionary.read():
  16.     if char.isalpha() == True:
  17.         currword.append(char)
  18.  
  19.     else:
  20.         currword = "".join(currword)
  21.         currword = currword.upper()
  22.         A = currword.count("A")
  23.         B = currword.count("B")
  24.         C = currword.count("C")
  25.         D = currword.count("D")
  26.         E = currword.count("E")
  27.         F = currword.count("F")
  28.  
  29.         if (A+B+C+D+E+F) == len(currword):
  30.             if currword not in allhexwords:
  31.                 allhexwords.append(currword)
  32.                 print("word found:",currword)
  33.                 if len(currword) == 6:
  34.                     lensixwords.append(currword)
  35.             currword = []
  36.            
  37.         else:
  38.             currword = []
  39.  
  40. allhexwords.sort()
  41. lensixwords.sort()
  42.  
  43. output1 = open("Hex Word Dictionary.txt","w")
  44.  
  45. for word in allhexwords:
  46.     output1.write(word+"\n")
  47.  
  48.  
  49.  
  50. output2 = open("Six Letter Hex Word Dictionary.txt","w")
  51.  
  52. for word in lensixwords:
  53.     output2.write(word+"\n")
  54.  
  55. dictionary.close()
  56. output1.close()
  57. output2.close()
  58.  
  59. print("\nAlphabetically ordered dictionary of hex words saved.")
  60. print("Please open newly created text files in the root folder.")
Advertisement
Add Comment
Please, Sign In to add comment