Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. #python program to unscramble a list of words given the list of unscrambled words  
  2. scrambled_words = ['AKSDO','ETECRHLVO', 'LPOE','IDAU','UZIUS','UCRAA','RBSUAU','RGAJUA', 'PEJE','AZMAD', 'IMNI','DOVLNARRE', 'SLXEU', 'BASA','UPETOGE', 'UTLARNE','ONTRPO','EDWOAO','TIOCNER','GNOYAGSNS', 'ALICALDC','IATF', 'RASONTATNIM', 'ESEDRMCE', 'MHCOI', 'NLACMER', 'TIINIIFN', 'TSOLU', 'LNETEBY', 'IRATASME', 'RFEIARR', 'DHNOA','SNNSIA', 'AAVLH','RFDO','OLOVV', 'ETSA', 'YTOTAO','UODPREA', 'ELGYE','HSIBUSIMIT', 'OOEMRFAAL', 'HAIATDUS', 'GNEOVSKLWA', 'CEHSRPO', 'NIADYHU', 'ITABGTU', 'MBALNIHGROI', 'CRLOSEORYL','IKZSUU','SAELT']    
  3.  
  4. with open("Newt.txt", 'r') as wlist:
  5.     unscrambled_words = wlist.read().split("\n")  
  6.  
  7. signatures = dict()
  8.  
  9. #looping through the list of unscrambled words
  10. for word in unscrambled_words:
  11.     #sorts the list of unscrambled words into ASCII order(i.e; AKSDO --> ADKOS) and removes whitespaces
  12.     s_word = ''.join(sorted(word.upper().replace(' ','')))
  13.  
  14.     #storing the sorted list in a dictionary, this gives each word in the unscrambled_list
  15.     #a signature and pairs it with its matching signature in the scrambled_list
  16.     signatures[s_word] = word
  17.  
  18. found_words = []
  19. #looping through list of scrambled words
  20. #sword = scrambled word
  21. for sword in scrambled_words:
  22.     s_word = ''.join(sorted(sword))
  23.     if s_word in signatures:
  24.         found_words.append(signatures[s_word])
  25.     else:
  26.         pass
  27.     print(scrambled_words.index(sword) + 1,'.' , sword, '=', signatures[s_word].title())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement