with open("042_words.txt") as f: for line in f: words=[w[1:-1] for w in line.split(",")] t=set([n*(n+1)/2 for n in range(1,101)]) print sum(sum(ord(a)-64 for a in w) in t for w in words)