42.py 475 B

1234567891011121314151617181920212223
  1. import string
  2. letterscore = dict(list(zip(string.ascii_lowercase, list(range(1, 27)))))
  3. triangle = [x*(x+1)/2 for x in range(1000)]
  4. f = open("words.txt", "r")
  5. f = f.read()
  6. f = f.strip().split(',')
  7. f.sort()
  8. for index in range(len(f)):
  9. f[index] = f[index][1:-1]
  10. wordlist = [x.lower() for x in f]
  11. trianglewords = 0
  12. for word in wordlist:
  13. wordscore = 0
  14. for char in word:
  15. wordscore += letterscore[char]
  16. if wordscore in triangle:
  17. trianglewords += 1
  18. print(trianglewords)