from math import sqrt score = lambda word: sum(ord(c)-ord('A')+1 for c in word) is_tn = lambda t: (sqrt(1 + 8*t) - 1) / 2 % 1 == 0 print ("Number of triangle words =", sum(is_tn(score(x[1:-1])) for x in open('words.txt').read().split(',')))