Guest User

Untitled

a guest
Dec 1st, 2020
68
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import requests
  2.  
  3. c10 = set()
  4. c9 = set()
  5.  
  6. # Get Scrabble words of length 10 and 9
  7. words_str = requests.get('http://norvig.com/ngrams/enable1.txt').content.decode('utf-8')
  8. for l in words_str.split('\n'):
  9.     l = l.strip()
  10.     if len(l) == 10 and 't' in l:
  11.         c10.add(l)
  12.     elif len(l) == 9:
  13.         c9.add(l)
  14.        
  15. # Sort the 9-letter ones
  16. c9_sorted = set(''.join(sorted(x)) for x in c9)
  17. #%%
  18. # Remove a t, sort, and see if it makes a word
  19. ct = 0
  20. transdelete_words = []
  21. for w in c10:
  22.     w1 = w.replace('t', '', 1)
  23.     w1_sorted = ''.join(sorted(w1))
  24.     if w1_sorted in c9_sorted:
  25.         ct += 1
  26.         transdelete_words.append(w)
  27.        
  28. print(len(c10))
  29. print(ct)
RAW Paste Data